1 /*
2 * %CopyrightBegin%
3
4 *
5 * Copyright Ericsson AB 2001-2017. All Rights Reserved.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * %CopyrightEnd%
20 */
21 /*
22 * hipe_bif1.c
23 *
24 * Performance analysis support.
25 */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 #include "sys.h"
30 #include "global.h"
31 #include "bif.h"
32 #include "big.h"
33 #include "error.h"
34 #include "beam_load.h"
35 #include "erl_vm.h"
36 #include "hipe_bif0.h"
37 #include "hipe_bif1.h"
38
hipe_bifs_call_count_on_1(BIF_ALIST_1)39 BIF_RETTYPE hipe_bifs_call_count_on_1(BIF_ALIST_1)
40 {
41 ErtsCodeInfo *ci;
42 Eterm *pc;
43 struct hipe_call_count *hcc;
44
45 ci = hipe_bifs_find_pc_from_mfa(BIF_ARG_1);
46 if (!ci)
47 BIF_ERROR(BIF_P, BADARG);
48 ASSERT(BeamIsOpCode(ci->op, op_i_func_info_IaaI));
49 pc = erts_codeinfo_to_code(ci);
50 if (BeamIsOpCode(pc[0], op_hipe_trap_call))
51 BIF_ERROR(BIF_P, BADARG);
52 if (BeamIsOpCode(pc[0], op_hipe_call_count))
53 BIF_RET(NIL);
54 hcc = erts_alloc(ERTS_ALC_T_HIPE_SL, sizeof(*hcc));
55 hcc->count = 0;
56 hcc->opcode = pc[0];
57 ci->u.hcc = hcc;
58 pc[0] = BeamOpCodeAddr(op_hipe_call_count);
59 BIF_RET(am_true);
60 }
61
hipe_bifs_call_count_off_1(BIF_ALIST_1)62 BIF_RETTYPE hipe_bifs_call_count_off_1(BIF_ALIST_1)
63 {
64 ErtsCodeInfo* ci;
65 Eterm *pc;
66 struct hipe_call_count *hcc;
67 unsigned count;
68
69 ci = hipe_bifs_find_pc_from_mfa(BIF_ARG_1);
70 if (!ci)
71 BIF_ERROR(BIF_P, BADARG);
72 ASSERT(BeamIsOpCode(ci->op, op_i_func_info_IaaI));
73 pc = erts_codeinfo_to_code(ci);
74 if (! BeamIsOpCode(pc[0], op_hipe_call_count))
75 BIF_RET(am_false);
76 hcc = ci->u.hcc;
77 count = hcc->count;
78 pc[0] = hcc->opcode;
79 ci->u.hcc = NULL;
80 erts_free(ERTS_ALC_T_HIPE_SL, hcc);
81 BIF_RET(make_small(count));
82 }
83
hipe_bifs_call_count_get_1(BIF_ALIST_1)84 BIF_RETTYPE hipe_bifs_call_count_get_1(BIF_ALIST_1)
85 {
86 ErtsCodeInfo* ci;
87 Eterm *pc;
88 struct hipe_call_count *hcc;
89
90 ci = hipe_bifs_find_pc_from_mfa(BIF_ARG_1);
91 if (!ci)
92 BIF_ERROR(BIF_P, BADARG);
93 ASSERT(BeamIsOpCode(ci->op, op_i_func_info_IaaI));
94 pc = erts_codeinfo_to_code(ci);
95 if (! BeamIsOpCode(pc[0], op_hipe_call_count))
96 BIF_RET(am_false);
97 hcc = ci->u.hcc;
98 BIF_RET(make_small(hcc->count));
99 }
100
hipe_bifs_call_count_clear_1(BIF_ALIST_1)101 BIF_RETTYPE hipe_bifs_call_count_clear_1(BIF_ALIST_1)
102 {
103 ErtsCodeInfo* ci;
104 Eterm *pc;
105 struct hipe_call_count *hcc;
106 unsigned count;
107
108 ci = hipe_bifs_find_pc_from_mfa(BIF_ARG_1);
109 if (!ci)
110 BIF_ERROR(BIF_P, BADARG);
111 ASSERT(BeamIsOpCode(ci->op, op_i_func_info_IaaI));
112 pc = erts_codeinfo_to_code(ci);
113 if (! BeamIsOpCode(pc[0], op_hipe_call_count))
114 BIF_RET(am_false);
115 hcc = ci->u.hcc;
116 count = hcc->count;
117 hcc->count = 0;
118 BIF_RET(make_small(count));
119 }
120
121 unsigned int hipe_trap_count;
122
hipe_bifs_trap_count_get_0(BIF_ALIST_0)123 BIF_RETTYPE hipe_bifs_trap_count_get_0(BIF_ALIST_0)
124 {
125 BIF_RET(make_small(hipe_trap_count));
126 }
127
hipe_bifs_trap_count_clear_0(BIF_ALIST_0)128 BIF_RETTYPE hipe_bifs_trap_count_clear_0(BIF_ALIST_0)
129 {
130 unsigned int count = hipe_trap_count;
131 hipe_trap_count = 0;
132 BIF_RET(make_small(count));
133 }
134