aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2015-10-15 20:10:46 +0200
committerBjörn-Egil Dahlberg <[email protected]>2015-12-07 19:34:39 +0100
commit2ae91c3ade0538500ff4dbda29ad539e595f64df (patch)
tree5d3e77bfd2c97b6391710b1030c766fedde0d3ca
parente656b6e26de27db6a4235961f7e667998d3a2832 (diff)
downloadotp-2ae91c3ade0538500ff4dbda29ad539e595f64df.tar.gz
otp-2ae91c3ade0538500ff4dbda29ad539e595f64df.tar.bz2
otp-2ae91c3ade0538500ff4dbda29ad539e595f64df.zip
erts: Change erts_internal:map_type/1 into term_type/1
to support other terms, not just maps
-rw-r--r--erts/emulator/beam/atom.h1
-rw-r--r--erts/emulator/beam/bif.tab2
-rw-r--r--erts/emulator/beam/erl_map.c25
-rw-r--r--erts/emulator/test/map_SUITE.erl4
-rw-r--r--erts/preloaded/ebin/erts_internal.beambin5964 -> 5988 bytes
-rw-r--r--erts/preloaded/src/erts_internal.erl12
-rw-r--r--lib/kernel/src/erts_debug.erl2
7 files changed, 28 insertions, 18 deletions
diff --git a/erts/emulator/beam/atom.h b/erts/emulator/beam/atom.h
index ead56c83d8..2c002ca92f 100644
--- a/erts/emulator/beam/atom.h
+++ b/erts/emulator/beam/atom.h
@@ -129,6 +129,7 @@ typedef enum {
(erts_is_atom_utf8_bytes((byte *) LSTR, sizeof(LSTR) - 1, (TERM)))
#define ERTS_DECL_AM(S) Eterm AM_ ## S = am_atom_put(#S, sizeof(#S) - 1)
#define ERTS_INIT_AM(S) AM_ ## S = am_atom_put(#S, sizeof(#S) - 1)
+#define ERTS_MAKE_AM(Str) am_atom_put(Str, sizeof(Str) - 1)
int atom_table_size(void); /* number of elements */
int atom_table_sz(void); /* table size in bytes, excluding stored objects */
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab
index c49a3ff313..07d4702b92 100644
--- a/erts/emulator/beam/bif.tab
+++ b/erts/emulator/beam/bif.tab
@@ -167,7 +167,7 @@ bif erts_internal:request_system_task/3
bif erts_internal:check_process_code/2
bif erts_internal:map_to_tuple_keys/1
-bif erts_internal:map_type/1
+bif erts_internal:term_type/1
bif erts_internal:map_hashmap_children/1
bif erts_internal:time_unit/0
diff --git a/erts/emulator/beam/erl_map.c b/erts/emulator/beam/erl_map.c
index 29b3024644..ac10b9a3e3 100644
--- a/erts/emulator/beam/erl_map.c
+++ b/erts/emulator/beam/erl_map.c
@@ -2698,29 +2698,38 @@ BIF_RETTYPE erts_internal_map_to_tuple_keys_1(BIF_ALIST_1) {
}
/*
- * erts_internal:map_type/1
+ * erts_internal:term_type/1
*
* Used in erts_debug:size/1
*/
-BIF_RETTYPE erts_internal_map_type_1(BIF_ALIST_1) {
- DECL_AM(hashmap);
- DECL_AM(hashmap_node);
- DECL_AM(flatmap);
+BIF_RETTYPE erts_internal_term_type_1(BIF_ALIST_1) {
if (is_map(BIF_ARG_1)) {
Eterm hdr = *(boxed_val(BIF_ARG_1));
ASSERT(is_header(hdr));
switch (hdr & _HEADER_MAP_SUBTAG_MASK) {
case HAMT_SUBTAG_HEAD_FLATMAP:
- BIF_RET(AM_flatmap);
+ BIF_RET(ERTS_MAKE_AM("flatmap"));
case HAMT_SUBTAG_HEAD_ARRAY:
case HAMT_SUBTAG_HEAD_BITMAP:
- BIF_RET(AM_hashmap);
+ BIF_RET(ERTS_MAKE_AM("hashmap"));
case HAMT_SUBTAG_NODE_BITMAP:
- BIF_RET(AM_hashmap_node);
+ BIF_RET(ERTS_MAKE_AM("hashmap_node"));
default:
erl_exit(1, "bad header");
}
+ } else if (is_immed(BIF_ARG_1)) {
+ if (is_small(BIF_ARG_1)) {
+ BIF_RET(ERTS_MAKE_AM("small"));
+ } else if (is_ifloat(BIF_ARG_1)) {
+ BIF_RET(ERTS_MAKE_AM("ifloat"));
+ }
+ } else if (is_boxed(BIF_ARG_1)) {
+ if (is_big(BIF_ARG_1)) {
+ BIF_RET(ERTS_MAKE_AM("big"));
+ } else if (is_hfloat(BIF_ARG_1)) {
+ BIF_RET(ERTS_MAKE_AM("hfloat"));
+ }
}
BIF_P->fvalue = BIF_ARG_1;
BIF_ERROR(BIF_P, BADMAP);
diff --git a/erts/emulator/test/map_SUITE.erl b/erts/emulator/test/map_SUITE.erl
index 6890c42b7a..bde0d408f3 100644
--- a/erts/emulator/test/map_SUITE.erl
+++ b/erts/emulator/test/map_SUITE.erl
@@ -2598,7 +2598,7 @@ hashmap_balance(KeyFun) ->
F = fun(I, {M0,Max0}) ->
Key = KeyFun(I),
M1 = M0#{Key => Key},
- Max1 = case erts_internal:map_type(M1) of
+ Max1 = case erts_internal:term_type(M1) of
hashmap ->
Nodes = hashmap_nodes(M1),
Avg = maps:size(M1) * 0.4,
@@ -3004,7 +3004,7 @@ t_gc_rare_map_overflow(Config) ->
Loop()
end),
FatMap = fatmap(34),
- false = (flatmap =:= erts_internal:map_type(FatMap)),
+ false = (flatmap =:= erts_internal:term_type(FatMap)),
t_gc_rare_map_overflow_do(Echo, FatMap, fun() -> erlang:garbage_collect() end),
diff --git a/erts/preloaded/ebin/erts_internal.beam b/erts/preloaded/ebin/erts_internal.beam
index dc8c711e1a..d63f79c327 100644
--- a/erts/preloaded/ebin/erts_internal.beam
+++ b/erts/preloaded/ebin/erts_internal.beam
Binary files differ
diff --git a/erts/preloaded/src/erts_internal.erl b/erts/preloaded/src/erts_internal.erl
index 7ed4efea4b..023af1579f 100644
--- a/erts/preloaded/src/erts_internal.erl
+++ b/erts/preloaded/src/erts_internal.erl
@@ -31,7 +31,7 @@
-export([await_port_send_result/3]).
-export([cmp_term/2]).
--export([map_to_tuple_keys/1, map_type/1, map_hashmap_children/1]).
+-export([map_to_tuple_keys/1, term_type/1, map_hashmap_children/1]).
-export([port_command/3, port_connect/2, port_close/1,
port_control/3, port_call/3, port_info/1, port_info/2]).
@@ -215,12 +215,12 @@ cmp_term(_A,_B) ->
map_to_tuple_keys(_M) ->
erlang:nif_error(undefined).
-%% return the internal map type
--spec map_type(M) -> Type when
- M :: map(),
- Type :: 'flatmap' | 'hashmap' | 'hashmap_node'.
+%% return the internal term type
+-spec term_type(M) -> Type when
+ M :: term(),
+ Type :: 'flatmap' | 'hashmap' | 'hashmap_node' | 'small' | 'big' | 'ifloat' | 'hfloat'.
-map_type(_M) ->
+term_type(_M) ->
erlang:nif_error(undefined).
%% return the internal hashmap sub-nodes from
diff --git a/lib/kernel/src/erts_debug.erl b/lib/kernel/src/erts_debug.erl
index 87f001fdf4..8e2b5ad214 100644
--- a/lib/kernel/src/erts_debug.erl
+++ b/lib/kernel/src/erts_debug.erl
@@ -243,7 +243,7 @@ map_size(Map,Seen0,Sum0) ->
%% is not allowed to leak anywhere. They are only allowed in
%% containers (cons cells and tuples, not maps), in gc and
%% in erts_debug:same/2
- case erts_internal:map_type(Map) of
+ case erts_internal:term_type(Map) of
flatmap ->
Kt = erts_internal:map_to_tuple_keys(Map),
Vs = maps:values(Map),