21 * questions.
22 *
23 */
24
25 #include "compiler/compileLog.hpp"
26 #include "interpreter/linkResolver.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/method.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/c2compiler.hpp"
31 #include "opto/castnode.hpp"
32 #include "opto/idealGraphPrinter.hpp"
33 #include "opto/locknode.hpp"
34 #include "opto/memnode.hpp"
35 #include "opto/opaquenode.hpp"
36 #include "opto/parse.hpp"
37 #include "opto/rootnode.hpp"
38 #include "opto/runtime.hpp"
39 #include "opto/type.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/safepointMechanism.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "utilities/bitMap.inline.hpp"
44 #include "utilities/copy.hpp"
45
46 // Static array so we can figure out which bytecodes stop us from compiling
47 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
48 // and eventually should be encapsulated in a proper class (gri 8/18/98).
49
50 #ifndef PRODUCT
51 uint nodes_created = 0;
52 uint methods_parsed = 0;
53 uint methods_seen = 0;
54 uint blocks_parsed = 0;
55 uint blocks_seen = 0;
56
57 uint explicit_null_checks_inserted = 0;
58 uint explicit_null_checks_elided = 0;
59 uint all_null_checks_found = 0;
60 uint implicit_null_checks = 0;
1116 _exits.map()->apply_replaced_nodes(_new_idx);
1117 }
1118
1119 //-----------------------------create_entry_map-------------------------------
1120 // Initialize our parser map to contain the types at method entry.
1121 // For OSR, the map contains a single RawPtr parameter.
1122 // Initial monitor locking for sync. methods is performed by do_method_entry.
1123 SafePointNode* Parse::create_entry_map() {
1124 // Check for really stupid bail-out cases.
1125 uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1126 if (len >= 32760) {
1127 // Bailout expected, this is a very rare edge case.
1128 C->record_method_not_compilable("too many local variables");
1129 return nullptr;
1130 }
1131
1132 // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1133 _caller->map()->delete_replaced_nodes();
1134
1135 // If this is an inlined method, we may have to do a receiver null check.
1136 if (_caller->has_method() && is_normal_parse() && !method()->is_static()) {
1137 GraphKit kit(_caller);
1138 kit.null_check_receiver_before_call(method());
1139 _caller = kit.transfer_exceptions_into_jvms();
1140 if (kit.stopped()) {
1141 _exits.add_exception_states_from(_caller);
1142 _exits.set_jvms(_caller);
1143 return nullptr;
1144 }
1145 }
1146
1147 assert(method() != nullptr, "parser must have a method");
1148
1149 // Create an initial safepoint to hold JVM state during parsing
1150 JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : nullptr);
1151 set_map(new SafePointNode(len, jvms));
1152 jvms->set_map(map());
1153 record_for_igvn(map());
1154 assert(jvms->endoff() == len, "correct jvms sizing");
1155
1156 SafePointNode* inmap = _caller->map();
1157 assert(inmap != nullptr, "must have inmap");
1158 // In case of null check on receiver above
1184 map()->init_req(i, top());
1185 }
1186
1187 SafePointNode* entry_map = stop();
1188 return entry_map;
1189 }
1190
1191 //-----------------------------do_method_entry--------------------------------
1192 // Emit any code needed in the pseudo-block before BCI zero.
1193 // The main thing to do is lock the receiver of a synchronized method.
1194 void Parse::do_method_entry() {
1195 set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1196 set_sp(0); // Java Stack Pointer
1197
1198 NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); )
1199
1200 if (C->env()->dtrace_method_probes()) {
1201 make_dtrace_method_entry(method());
1202 }
1203
1204 #ifdef ASSERT
1205 // Narrow receiver type when it is too broad for the method being parsed.
1206 if (!method()->is_static()) {
1207 ciInstanceKlass* callee_holder = method()->holder();
1208 const Type* holder_type = TypeInstPtr::make(TypePtr::BotPTR, callee_holder, Type::trust_interfaces);
1209
1210 Node* receiver_obj = local(0);
1211 const TypeInstPtr* receiver_type = _gvn.type(receiver_obj)->isa_instptr();
1212
1213 if (receiver_type != nullptr && !receiver_type->higher_equal(holder_type)) {
1214 // Receiver should always be a subtype of callee holder.
1215 // But, since C2 type system doesn't properly track interfaces,
1216 // the invariant can't be expressed in the type system for default methods.
1217 // Example: for unrelated C <: I and D <: I, (C `meet` D) = Object </: I.
1218 assert(callee_holder->is_interface(), "missing subtype check");
1219
1220 // Perform dynamic receiver subtype check against callee holder class w/ a halt on failure.
1221 Node* holder_klass = _gvn.makecon(TypeKlassPtr::make(callee_holder, Type::trust_interfaces));
1222 Node* not_subtype_ctrl = gen_subtype_check(receiver_obj, holder_klass);
1223 assert(!stopped(), "not a subtype");
2152
2153 Node* fast_io = call->in(TypeFunc::I_O);
2154 Node* fast_mem = call->in(TypeFunc::Memory);
2155 // These two phis are pre-filled with copies of of the fast IO and Memory
2156 Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO);
2157 Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
2158
2159 result_rgn->init_req(2, control());
2160 io_phi ->init_req(2, i_o());
2161 mem_phi ->init_req(2, reset_memory());
2162
2163 set_all_memory( _gvn.transform(mem_phi) );
2164 set_i_o( _gvn.transform(io_phi) );
2165 }
2166
2167 set_control( _gvn.transform(result_rgn) );
2168 }
2169
2170 // Add check to deoptimize once holder klass is fully initialized.
2171 void Parse::clinit_deopt() {
2172 assert(C->has_method(), "only for normal compilations");
2173 assert(depth() == 1, "only for main compiled method");
2174 assert(is_normal_parse(), "no barrier needed on osr entry");
2175 assert(!method()->holder()->is_not_initialized(), "initialization should have been started");
2176
2177 set_parse_bci(0);
2178
2179 Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
2180 guard_klass_being_initialized(holder);
2181 }
2182
2183 //------------------------------return_current---------------------------------
2184 // Append current _map to _exit_return
2185 void Parse::return_current(Node* value) {
2186 if (method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2187 call_register_finalizer();
2188 }
2189
2190 // Do not set_parse_bci, so that return goo is credited to the return insn.
2191 set_bci(InvocationEntryBci);
|
21 * questions.
22 *
23 */
24
25 #include "compiler/compileLog.hpp"
26 #include "interpreter/linkResolver.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/method.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/c2compiler.hpp"
31 #include "opto/castnode.hpp"
32 #include "opto/idealGraphPrinter.hpp"
33 #include "opto/locknode.hpp"
34 #include "opto/memnode.hpp"
35 #include "opto/opaquenode.hpp"
36 #include "opto/parse.hpp"
37 #include "opto/rootnode.hpp"
38 #include "opto/runtime.hpp"
39 #include "opto/type.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/runtimeUpcalls.hpp"
42 #include "runtime/safepointMechanism.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "utilities/bitMap.inline.hpp"
45 #include "utilities/copy.hpp"
46
47 // Static array so we can figure out which bytecodes stop us from compiling
48 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
49 // and eventually should be encapsulated in a proper class (gri 8/18/98).
50
51 #ifndef PRODUCT
52 uint nodes_created = 0;
53 uint methods_parsed = 0;
54 uint methods_seen = 0;
55 uint blocks_parsed = 0;
56 uint blocks_seen = 0;
57
58 uint explicit_null_checks_inserted = 0;
59 uint explicit_null_checks_elided = 0;
60 uint all_null_checks_found = 0;
61 uint implicit_null_checks = 0;
1117 _exits.map()->apply_replaced_nodes(_new_idx);
1118 }
1119
1120 //-----------------------------create_entry_map-------------------------------
1121 // Initialize our parser map to contain the types at method entry.
1122 // For OSR, the map contains a single RawPtr parameter.
1123 // Initial monitor locking for sync. methods is performed by do_method_entry.
1124 SafePointNode* Parse::create_entry_map() {
1125 // Check for really stupid bail-out cases.
1126 uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1127 if (len >= 32760) {
1128 // Bailout expected, this is a very rare edge case.
1129 C->record_method_not_compilable("too many local variables");
1130 return nullptr;
1131 }
1132
1133 // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1134 _caller->map()->delete_replaced_nodes();
1135
1136 // If this is an inlined method, we may have to do a receiver null check.
1137 if (_caller->has_method() && is_normal_parse()) {
1138 GraphKit kit(_caller);
1139 if (!method()->is_static()) {
1140 kit.null_check_receiver_before_call(method());
1141 } else if (C->do_clinit_barriers() && C->needs_clinit_barrier(method()->holder(), _caller->method())) {
1142 ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
1143 const int nargs = declared_method->arg_size();
1144 kit.inc_sp(nargs);
1145 Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
1146 kit.guard_klass_is_initialized(holder);
1147 kit.dec_sp(nargs);
1148 }
1149 _caller = kit.transfer_exceptions_into_jvms();
1150 if (kit.stopped()) {
1151 _exits.add_exception_states_from(_caller);
1152 _exits.set_jvms(_caller);
1153 return nullptr;
1154 }
1155 }
1156
1157 assert(method() != nullptr, "parser must have a method");
1158
1159 // Create an initial safepoint to hold JVM state during parsing
1160 JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : nullptr);
1161 set_map(new SafePointNode(len, jvms));
1162 jvms->set_map(map());
1163 record_for_igvn(map());
1164 assert(jvms->endoff() == len, "correct jvms sizing");
1165
1166 SafePointNode* inmap = _caller->map();
1167 assert(inmap != nullptr, "must have inmap");
1168 // In case of null check on receiver above
1194 map()->init_req(i, top());
1195 }
1196
1197 SafePointNode* entry_map = stop();
1198 return entry_map;
1199 }
1200
1201 //-----------------------------do_method_entry--------------------------------
1202 // Emit any code needed in the pseudo-block before BCI zero.
1203 // The main thing to do is lock the receiver of a synchronized method.
1204 void Parse::do_method_entry() {
1205 set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1206 set_sp(0); // Java Stack Pointer
1207
1208 NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); )
1209
1210 if (C->env()->dtrace_method_probes()) {
1211 make_dtrace_method_entry(method());
1212 }
1213
1214 install_on_method_entry_runtime_upcalls(method());
1215
1216 #ifdef ASSERT
1217 // Narrow receiver type when it is too broad for the method being parsed.
1218 if (!method()->is_static()) {
1219 ciInstanceKlass* callee_holder = method()->holder();
1220 const Type* holder_type = TypeInstPtr::make(TypePtr::BotPTR, callee_holder, Type::trust_interfaces);
1221
1222 Node* receiver_obj = local(0);
1223 const TypeInstPtr* receiver_type = _gvn.type(receiver_obj)->isa_instptr();
1224
1225 if (receiver_type != nullptr && !receiver_type->higher_equal(holder_type)) {
1226 // Receiver should always be a subtype of callee holder.
1227 // But, since C2 type system doesn't properly track interfaces,
1228 // the invariant can't be expressed in the type system for default methods.
1229 // Example: for unrelated C <: I and D <: I, (C `meet` D) = Object </: I.
1230 assert(callee_holder->is_interface(), "missing subtype check");
1231
1232 // Perform dynamic receiver subtype check against callee holder class w/ a halt on failure.
1233 Node* holder_klass = _gvn.makecon(TypeKlassPtr::make(callee_holder, Type::trust_interfaces));
1234 Node* not_subtype_ctrl = gen_subtype_check(receiver_obj, holder_klass);
1235 assert(!stopped(), "not a subtype");
2164
2165 Node* fast_io = call->in(TypeFunc::I_O);
2166 Node* fast_mem = call->in(TypeFunc::Memory);
2167 // These two phis are pre-filled with copies of of the fast IO and Memory
2168 Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO);
2169 Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
2170
2171 result_rgn->init_req(2, control());
2172 io_phi ->init_req(2, i_o());
2173 mem_phi ->init_req(2, reset_memory());
2174
2175 set_all_memory( _gvn.transform(mem_phi) );
2176 set_i_o( _gvn.transform(io_phi) );
2177 }
2178
2179 set_control( _gvn.transform(result_rgn) );
2180 }
2181
2182 // Add check to deoptimize once holder klass is fully initialized.
2183 void Parse::clinit_deopt() {
2184 if (method()->holder()->is_initialized()) {
2185 return; // in case do_clinit_barriers() is true
2186 }
2187 assert(C->has_method(), "only for normal compilations");
2188 assert(depth() == 1, "only for main compiled method");
2189 assert(is_normal_parse(), "no barrier needed on osr entry");
2190 assert(!method()->holder()->is_not_initialized(), "initialization should have been started");
2191
2192 set_parse_bci(0);
2193
2194 Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
2195 guard_klass_being_initialized(holder);
2196 }
2197
2198 //------------------------------return_current---------------------------------
2199 // Append current _map to _exit_return
2200 void Parse::return_current(Node* value) {
2201 if (method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2202 call_register_finalizer();
2203 }
2204
2205 // Do not set_parse_bci, so that return goo is credited to the return insn.
2206 set_bci(InvocationEntryBci);
|