< prev index next >

src/hotspot/share/opto/parse1.cpp

Print this page

  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/method.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/c2compiler.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/idealGraphPrinter.hpp"
  34 #include "opto/locknode.hpp"
  35 #include "opto/memnode.hpp"
  36 #include "opto/opaquenode.hpp"
  37 #include "opto/parse.hpp"
  38 #include "opto/rootnode.hpp"
  39 #include "opto/runtime.hpp"
  40 #include "opto/type.hpp"
  41 #include "runtime/handles.inline.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() && !method()->is_static()) {
1138     GraphKit kit(_caller);
1139     kit.null_check_receiver_before_call(method());









1140     _caller = kit.transfer_exceptions_into_jvms();
1141     if (kit.stopped()) {
1142       _exits.add_exception_states_from(_caller);
1143       _exits.set_jvms(_caller);
1144       return nullptr;
1145     }
1146   }
1147 
1148   assert(method() != nullptr, "parser must have a method");
1149 
1150   // Create an initial safepoint to hold JVM state during parsing
1151   JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : nullptr);
1152   set_map(new SafePointNode(len, jvms));
1153   jvms->set_map(map());
1154   record_for_igvn(map());
1155   assert(jvms->endoff() == len, "correct jvms sizing");
1156 
1157   SafePointNode* inmap = _caller->map();
1158   assert(inmap != nullptr, "must have inmap");
1159   // In case of null check on receiver above

1185     map()->init_req(i, top());
1186   }
1187 
1188   SafePointNode* entry_map = stop();
1189   return entry_map;
1190 }
1191 
1192 //-----------------------------do_method_entry--------------------------------
1193 // Emit any code needed in the pseudo-block before BCI zero.
1194 // The main thing to do is lock the receiver of a synchronized method.
1195 void Parse::do_method_entry() {
1196   set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1197   set_sp(0);                         // Java Stack Pointer
1198 
1199   NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); )
1200 
1201   if (C->env()->dtrace_method_probes()) {
1202     make_dtrace_method_entry(method());
1203   }
1204 


1205 #ifdef ASSERT
1206   // Narrow receiver type when it is too broad for the method being parsed.
1207   if (!method()->is_static()) {
1208     ciInstanceKlass* callee_holder = method()->holder();
1209     const Type* holder_type = TypeInstPtr::make(TypePtr::BotPTR, callee_holder, Type::trust_interfaces);
1210 
1211     Node* receiver_obj = local(0);
1212     const TypeInstPtr* receiver_type = _gvn.type(receiver_obj)->isa_instptr();
1213 
1214     if (receiver_type != nullptr && !receiver_type->higher_equal(holder_type)) {
1215       // Receiver should always be a subtype of callee holder.
1216       // But, since C2 type system doesn't properly track interfaces,
1217       // the invariant can't be expressed in the type system for default methods.
1218       // Example: for unrelated C <: I and D <: I, (C `meet` D) = Object </: I.
1219       assert(callee_holder->is_interface(), "missing subtype check");
1220 
1221       // Perform dynamic receiver subtype check against callee holder class w/ a halt on failure.
1222       Node* holder_klass = _gvn.makecon(TypeKlassPtr::make(callee_holder, Type::trust_interfaces));
1223       Node* not_subtype_ctrl = gen_subtype_check(receiver_obj, holder_klass);
1224       assert(!stopped(), "not a subtype");

2153 
2154     Node* fast_io  = call->in(TypeFunc::I_O);
2155     Node* fast_mem = call->in(TypeFunc::Memory);
2156     // These two phis are pre-filled with copies of of the fast IO and Memory
2157     Node* io_phi   = PhiNode::make(result_rgn, fast_io,  Type::ABIO);
2158     Node* mem_phi  = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
2159 
2160     result_rgn->init_req(2, control());
2161     io_phi    ->init_req(2, i_o());
2162     mem_phi   ->init_req(2, reset_memory());
2163 
2164     set_all_memory( _gvn.transform(mem_phi) );
2165     set_i_o(        _gvn.transform(io_phi) );
2166   }
2167 
2168   set_control( _gvn.transform(result_rgn) );
2169 }
2170 
2171 // Add check to deoptimize once holder klass is fully initialized.
2172 void Parse::clinit_deopt() {



2173   assert(C->has_method(), "only for normal compilations");
2174   assert(depth() == 1, "only for main compiled method");
2175   assert(is_normal_parse(), "no barrier needed on osr entry");
2176   assert(!method()->holder()->is_not_initialized(), "initialization should have been started");
2177 
2178   set_parse_bci(0);
2179 
2180   Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
2181   guard_klass_being_initialized(holder);
2182 }
2183 
2184 //------------------------------return_current---------------------------------
2185 // Append current _map to _exit_return
2186 void Parse::return_current(Node* value) {
2187   if (method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2188     call_register_finalizer();
2189   }
2190 
2191   // Do not set_parse_bci, so that return goo is credited to the return insn.
2192   set_bci(InvocationEntryBci);

  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/method.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/c2compiler.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/idealGraphPrinter.hpp"
  34 #include "opto/locknode.hpp"
  35 #include "opto/memnode.hpp"
  36 #include "opto/opaquenode.hpp"
  37 #include "opto/parse.hpp"
  38 #include "opto/rootnode.hpp"
  39 #include "opto/runtime.hpp"
  40 #include "opto/type.hpp"
  41 #include "runtime/handles.inline.hpp"
  42 #include "runtime/runtimeUpcalls.hpp"
  43 #include "runtime/safepointMechanism.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "utilities/bitMap.inline.hpp"
  46 #include "utilities/copy.hpp"
  47 
  48 // Static array so we can figure out which bytecodes stop us from compiling
  49 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
  50 // and eventually should be encapsulated in a proper class (gri 8/18/98).
  51 
  52 #ifndef PRODUCT
  53 uint nodes_created             = 0;
  54 uint methods_parsed            = 0;
  55 uint methods_seen              = 0;
  56 uint blocks_parsed             = 0;
  57 uint blocks_seen               = 0;
  58 
  59 uint explicit_null_checks_inserted = 0;
  60 uint explicit_null_checks_elided   = 0;
  61 uint all_null_checks_found         = 0;
  62 uint implicit_null_checks          = 0;

1118   _exits.map()->apply_replaced_nodes(_new_idx);
1119 }
1120 
1121 //-----------------------------create_entry_map-------------------------------
1122 // Initialize our parser map to contain the types at method entry.
1123 // For OSR, the map contains a single RawPtr parameter.
1124 // Initial monitor locking for sync. methods is performed by do_method_entry.
1125 SafePointNode* Parse::create_entry_map() {
1126   // Check for really stupid bail-out cases.
1127   uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1128   if (len >= 32760) {
1129     // Bailout expected, this is a very rare edge case.
1130     C->record_method_not_compilable("too many local variables");
1131     return nullptr;
1132   }
1133 
1134   // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1135   _caller->map()->delete_replaced_nodes();
1136 
1137   // If this is an inlined method, we may have to do a receiver null check.
1138   if (_caller->has_method() && is_normal_parse()) {
1139     GraphKit kit(_caller);
1140     if (!method()->is_static()) {
1141       kit.null_check_receiver_before_call(method());
1142     } else if (C->do_clinit_barriers() && C->needs_clinit_barrier(method()->holder(), _caller->method())) {
1143       ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
1144       const int nargs = declared_method->arg_size();
1145       kit.inc_sp(nargs);
1146       Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
1147       kit.guard_klass_is_initialized(holder);
1148       kit.dec_sp(nargs);
1149     }
1150     _caller = kit.transfer_exceptions_into_jvms();
1151     if (kit.stopped()) {
1152       _exits.add_exception_states_from(_caller);
1153       _exits.set_jvms(_caller);
1154       return nullptr;
1155     }
1156   }
1157 
1158   assert(method() != nullptr, "parser must have a method");
1159 
1160   // Create an initial safepoint to hold JVM state during parsing
1161   JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : nullptr);
1162   set_map(new SafePointNode(len, jvms));
1163   jvms->set_map(map());
1164   record_for_igvn(map());
1165   assert(jvms->endoff() == len, "correct jvms sizing");
1166 
1167   SafePointNode* inmap = _caller->map();
1168   assert(inmap != nullptr, "must have inmap");
1169   // In case of null check on receiver above

1195     map()->init_req(i, top());
1196   }
1197 
1198   SafePointNode* entry_map = stop();
1199   return entry_map;
1200 }
1201 
1202 //-----------------------------do_method_entry--------------------------------
1203 // Emit any code needed in the pseudo-block before BCI zero.
1204 // The main thing to do is lock the receiver of a synchronized method.
1205 void Parse::do_method_entry() {
1206   set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1207   set_sp(0);                         // Java Stack Pointer
1208 
1209   NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); )
1210 
1211   if (C->env()->dtrace_method_probes()) {
1212     make_dtrace_method_entry(method());
1213   }
1214 
1215   install_on_method_entry_runtime_upcalls(method());
1216 
1217 #ifdef ASSERT
1218   // Narrow receiver type when it is too broad for the method being parsed.
1219   if (!method()->is_static()) {
1220     ciInstanceKlass* callee_holder = method()->holder();
1221     const Type* holder_type = TypeInstPtr::make(TypePtr::BotPTR, callee_holder, Type::trust_interfaces);
1222 
1223     Node* receiver_obj = local(0);
1224     const TypeInstPtr* receiver_type = _gvn.type(receiver_obj)->isa_instptr();
1225 
1226     if (receiver_type != nullptr && !receiver_type->higher_equal(holder_type)) {
1227       // Receiver should always be a subtype of callee holder.
1228       // But, since C2 type system doesn't properly track interfaces,
1229       // the invariant can't be expressed in the type system for default methods.
1230       // Example: for unrelated C <: I and D <: I, (C `meet` D) = Object </: I.
1231       assert(callee_holder->is_interface(), "missing subtype check");
1232 
1233       // Perform dynamic receiver subtype check against callee holder class w/ a halt on failure.
1234       Node* holder_klass = _gvn.makecon(TypeKlassPtr::make(callee_holder, Type::trust_interfaces));
1235       Node* not_subtype_ctrl = gen_subtype_check(receiver_obj, holder_klass);
1236       assert(!stopped(), "not a subtype");

2165 
2166     Node* fast_io  = call->in(TypeFunc::I_O);
2167     Node* fast_mem = call->in(TypeFunc::Memory);
2168     // These two phis are pre-filled with copies of of the fast IO and Memory
2169     Node* io_phi   = PhiNode::make(result_rgn, fast_io,  Type::ABIO);
2170     Node* mem_phi  = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
2171 
2172     result_rgn->init_req(2, control());
2173     io_phi    ->init_req(2, i_o());
2174     mem_phi   ->init_req(2, reset_memory());
2175 
2176     set_all_memory( _gvn.transform(mem_phi) );
2177     set_i_o(        _gvn.transform(io_phi) );
2178   }
2179 
2180   set_control( _gvn.transform(result_rgn) );
2181 }
2182 
2183 // Add check to deoptimize once holder klass is fully initialized.
2184 void Parse::clinit_deopt() {
2185   if (method()->holder()->is_initialized()) {
2186     return; // in case do_clinit_barriers() is true
2187   }
2188   assert(C->has_method(), "only for normal compilations");
2189   assert(depth() == 1, "only for main compiled method");
2190   assert(is_normal_parse(), "no barrier needed on osr entry");
2191   assert(!method()->holder()->is_not_initialized(), "initialization should have been started");
2192 
2193   set_parse_bci(0);
2194 
2195   Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
2196   guard_klass_being_initialized(holder);
2197 }
2198 
2199 //------------------------------return_current---------------------------------
2200 // Append current _map to _exit_return
2201 void Parse::return_current(Node* value) {
2202   if (method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2203     call_register_finalizer();
2204   }
2205 
2206   // Do not set_parse_bci, so that return goo is credited to the return insn.
2207   set_bci(InvocationEntryBci);
< prev index next >