aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/hipe_SUITE.erl
diff options
context:
space:
mode:
authorMagnus Lång <[email protected]>2016-05-23 15:41:31 +0200
committerMagnus Lång <[email protected]>2016-07-06 16:08:20 +0200
commitf0131c58c42a286c8b3f611b47106393a37197b6 (patch)
treecaefc37baef32b065e69f23cc363a83ff70dcd12 /erts/emulator/test/hipe_SUITE.erl
parent3b409021a70427bb2fe3834707edf822b6afce2d (diff)
downloadotp-f0131c58c42a286c8b3f611b47106393a37197b6.tar.gz
otp-f0131c58c42a286c8b3f611b47106393a37197b6.tar.bz2
otp-f0131c58c42a286c8b3f611b47106393a37197b6.zip
check_process_code: Sweep HiPE stack for literals
Because check_process_code neglected checking the HiPE stack for references to the literal area, such references would survive the purge and subsequent deletion of a module and its literal area. These dangling references would then cause incorrect behaviour or even hard crashes of the VM. By simply adding a scan of the HiPE stack to check_process_code and erts_garbage_collect_literals, this problem is fixed. In order to support full stack walks without deleting the graylimit trap, a new stack walking interface function, nstack_walk_init_sdesc_ignore_trap() was introduced.
Diffstat (limited to 'erts/emulator/test/hipe_SUITE.erl')
-rw-r--r--erts/emulator/test/hipe_SUITE.erl64
1 files changed, 64 insertions, 0 deletions
diff --git a/erts/emulator/test/hipe_SUITE.erl b/erts/emulator/test/hipe_SUITE.erl
new file mode 100644
index 0000000000..3e682b8d88
--- /dev/null
+++ b/erts/emulator/test/hipe_SUITE.erl
@@ -0,0 +1,64 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2016. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(hipe_SUITE).
+-export([all/0, t_copy_literals/1]).
+
+all() ->
+ case erlang:system_info(hipe_architecture) of
+ undefined -> {skip, "HiPE is disabled"};
+ _ -> [t_copy_literals]
+ end.
+
+t_copy_literals(doc) ->
+ "Check that BEAM literals referenced from HiPE stack are copied by"
+ " check_process_code";
+t_copy_literals(Config) when is_list(Config) ->
+ %% Compile the the ref_cell and literals modules.
+ Data = proplists:get_value(data_dir, Config),
+ Priv = proplists:get_value(priv_dir, Config),
+ RefFile = filename:join(Data, "ref_cell"),
+ {ok,ref_cell} = c:c(RefFile, [{outdir,Priv},native]),
+ true = code:is_module_native(ref_cell),
+ LitFile = filename:join(Data, "literals"),
+ {ok,literals} = c:c(LitFile, [{outdir,Priv}]),
+
+ %% store references to literals on HiPE stacks
+ PA = ref_cell:start_link(),
+ ref_cell:call(PA, {put_res_of, fun literals:a/0}),
+ PB = ref_cell:start_link_deep(),
+ ref_cell:call(PB, {put_res_of, fun literals:b/0}),
+
+ %% purge the literals
+ _ = (catch erlang:purge_module(literals)),
+ true = erlang:delete_module(literals),
+ true = erlang:purge_module(literals),
+
+ %% check that the ex-literals are ok
+ [a,b,c] = ref_cell:call(PA, get),
+ {a,b,c} = ref_cell:call(PB, get),
+
+ %% cleanup
+ ref_cell:call(PA, done),
+ ref_cell:call(PB, done),
+ _ = (catch erlang:purge_module(ref_cell)),
+ true = erlang:delete_module(ref_cell),
+ true = erlang:purge_module(ref_cell),
+ ok.