1 /*
2 * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "asm/assembler.hpp"
27 #include "interpreter/interpreter.hpp"
28 #include "interpreter/interpreterRuntime.hpp"
29 #include "interpreter/zero/bytecodeInterpreter.hpp"
30 #include "interpreter/zero/zeroInterpreter.hpp"
31 #include "oops/method.hpp"
32 #include "zeroInterpreterGenerator.hpp"
33
34 ZeroInterpreterGenerator::ZeroInterpreterGenerator(): AbstractInterpreterGenerator() {
35 generate_all();
36 }
37
38 void ZeroInterpreterGenerator::generate_all() {
39 { CodeletMark cm(_masm, "slow signature handler");
40 AbstractInterpreter::_slow_signature_handler = generate_slow_signature_handler();
41 }
42
43 #define method_entry(kind) Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind)
44
45 { CodeletMark cm(_masm, "(kind = frame_manager)");
46 // all non-native method kinds
47 method_entry(zerolocals);
48 method_entry(zerolocals_synchronized);
49 method_entry(empty);
50 method_entry(getter);
51 method_entry(setter);
52 method_entry(abstract);
53 method_entry(java_lang_math_sin );
54 method_entry(java_lang_math_cos );
55 method_entry(java_lang_math_tan );
56 method_entry(java_lang_math_sinh );
57 method_entry(java_lang_math_tanh );
58 method_entry(java_lang_math_cbrt );
59 method_entry(java_lang_math_abs );
60 method_entry(java_lang_math_sqrt );
61 method_entry(java_lang_math_sqrt_strict);
62 method_entry(java_lang_math_log );
63 method_entry(java_lang_math_log10 );
64 method_entry(java_lang_math_pow );
65 method_entry(java_lang_math_exp );
66 method_entry(java_lang_math_fmaD );
67 method_entry(java_lang_math_fmaF );
68 method_entry(java_lang_ref_reference_get0);
69
70 AbstractInterpreter::initialize_method_handle_entries();
71
72 method_entry(native);
73 method_entry(native_synchronized);
74 }
75
76 #undef method_entry
77 }
78
79 // Generate method entries
80 address ZeroInterpreterGenerator::generate_method_entry(
81 AbstractInterpreter::MethodKind kind) {
82 // determine code generation flags
83 bool native = false;
84 bool synchronized = false;
85 address entry_point = nullptr;
86
87 switch (kind) {
88 case Interpreter::zerolocals : break;
89 case Interpreter::zerolocals_synchronized: synchronized = true; break;
90 case Interpreter::native : native = true; break;
91 case Interpreter::native_synchronized : native = true; synchronized = true; break;
92 case Interpreter::empty : entry_point = generate_empty_entry(); break;
93 case Interpreter::getter : entry_point = generate_getter_entry(); break;
94 case Interpreter::setter : entry_point = generate_setter_entry(); break;
95 case Interpreter::abstract : entry_point = generate_abstract_entry(); break;
96
97 case Interpreter::java_lang_math_sin : // fall thru
98 case Interpreter::java_lang_math_cos : // fall thru
99 case Interpreter::java_lang_math_tan : // fall thru
100 case Interpreter::java_lang_math_sinh : // fall thru
101 case Interpreter::java_lang_math_tanh : // fall thru
102 case Interpreter::java_lang_math_cbrt : // fall thru
103 case Interpreter::java_lang_math_abs : // fall thru
104 case Interpreter::java_lang_math_log : // fall thru
105 case Interpreter::java_lang_math_log10 : // fall thru
106 case Interpreter::java_lang_math_sqrt : // fall thru
107 case Interpreter::java_lang_math_sqrt_strict: // fall thru
108 case Interpreter::java_lang_math_pow : // fall thru
109 case Interpreter::java_lang_math_exp : // fall thru
110 case Interpreter::java_lang_math_fmaD : // fall thru
111 case Interpreter::java_lang_math_fmaF : entry_point = generate_math_entry(kind); break;
112 case Interpreter::java_lang_ref_reference_get0
113 : entry_point = generate_Reference_get_entry(); break;
114 default:
115 fatal("unexpected method kind: %d", kind);
116 break;
117 }
118
119 if (entry_point) {
120 return entry_point;
121 }
122
123 // We expect the normal and native entry points to be generated first so we can reuse them.
124 if (native) {
125 entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::native_synchronized : Interpreter::native);
126 if (entry_point == nullptr) {
127 entry_point = generate_native_entry(synchronized, false);
128 }
129 } else {
130 entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::zerolocals_synchronized : Interpreter::zerolocals);
131 if (entry_point == nullptr) {
132 entry_point = generate_normal_entry(synchronized, false);
133 }
134 }
135
136 return entry_point;
137 }
138
139 address ZeroInterpreterGenerator::generate_slow_signature_handler() {
140 _masm->advance(1);
141 return (address) InterpreterRuntime::slow_signature_handler;
142 }
143
144 address ZeroInterpreterGenerator::generate_math_entry(
145 AbstractInterpreter::MethodKind kind) {
146 if (!InlineIntrinsics)
147 return nullptr;
148
149 Unimplemented();
150 return nullptr;
151 }
152
153 address ZeroInterpreterGenerator::generate_abstract_entry() {
154 return generate_entry((address) ShouldNotCallThisEntry());
155 }
156
157 address ZeroInterpreterGenerator::generate_empty_entry() {
158 if (!UseFastEmptyMethods)
159 return nullptr;
160
161 return generate_entry((address) ZeroInterpreter::empty_entry);
162 }
163
164 address ZeroInterpreterGenerator::generate_getter_entry() {
165 if (!UseFastAccessorMethods)
166 return nullptr;
167
168 return generate_entry((address) ZeroInterpreter::getter_entry);
169 }
170
171 address ZeroInterpreterGenerator::generate_setter_entry() {
172 if (!UseFastAccessorMethods)
173 return nullptr;
174
175 return generate_entry((address) ZeroInterpreter::setter_entry);
176 }
177
178 address ZeroInterpreterGenerator::generate_Reference_get_entry(void) {
179 return generate_entry((address) ZeroInterpreter::Reference_get_entry);
180 }
181
182 address ZeroInterpreterGenerator::generate_native_entry(bool synchronized, bool runtime_upcalls) {
183 return generate_entry((address) ZeroInterpreter::native_entry);
184 }
185
186 address ZeroInterpreterGenerator::generate_normal_entry(bool synchronized, bool runtime_upcalls) {
187 return generate_entry((address) ZeroInterpreter::normal_entry);
188 }