< prev index next >

src/hotspot/share/jvmci/jvmciRuntime.cpp

Print this page




  92   JavaThread* thread = JavaThread::current();
  93   RegisterMap reg_map(thread, false);
  94   frame runtime_frame = thread->last_frame();
  95   frame caller_frame = runtime_frame.sender(&reg_map);
  96   assert(caller_frame.is_compiled_frame(), "must be compiled");
  97   return caller_frame.is_deoptimized_frame();
  98 }
  99 
 100 // Stress deoptimization
 101 static void deopt_caller() {
 102   if ( !caller_is_deopted()) {
 103     JavaThread* thread = JavaThread::current();
 104     RegisterMap reg_map(thread, false);
 105     frame runtime_frame = thread->last_frame();
 106     frame caller_frame = runtime_frame.sender(&reg_map);
 107     Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
 108     assert(caller_is_deopted(), "Must be deoptimized");
 109   }
 110 }
 111 
 112 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance(JavaThread* thread, Klass* klass))
































 113   JRT_BLOCK;
 114   assert(klass->is_klass(), "not a class");
 115   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 116   InstanceKlass* ik = InstanceKlass::cast(klass);


 117   ik->check_valid_for_instantiation(true, CHECK);








 118   // make sure klass is initialized
 119   ik->initialize(CHECK);

 120   // allocate instance and return via TLS
 121   oop obj = ik->allocate_instance(CHECK);
 122   thread->set_vm_result(obj);

 123   JRT_BLOCK_END;
 124   SharedRuntime::on_slowpath_allocation_exit(thread);
 125 JRT_END
 126 
 127 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length))
 128   JRT_BLOCK;
 129   // Note: no handle for klass needed since they are not used
 130   //       anymore after new_objArray() and no GC can happen before.
 131   //       (This may have to change if this code changes!)
 132   assert(array_klass->is_klass(), "not a class");
 133   oop obj;
 134   if (array_klass->is_typeArray_klass()) {
 135     BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type();

 136     obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 137   } else {
 138     Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
 139     Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();

 140     obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 141   }
 142   thread->set_vm_result(obj);
 143   // This is pretty rare but this runtime patch is stressful to deoptimization
 144   // if we deoptimize here so force a deopt to stress the path.
 145   if (DeoptimizeALot) {
 146     static int deopts = 0;
 147     // Alternate between deoptimizing and raising an error (which will also cause a deopt)
 148     if (deopts++ % 2 == 0) {



 149       ResourceMark rm(THREAD);
 150       THROW(vmSymbols::java_lang_OutOfMemoryError());

 151     } else {
 152       deopt_caller();
 153     }
 154   }
 155   JRT_BLOCK_END;
 156   SharedRuntime::on_slowpath_allocation_exit(thread);
 157 JRT_END
 158 
 159 JRT_ENTRY(void, JVMCIRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))
 160   assert(klass->is_klass(), "not a class");
 161   assert(rank >= 1, "rank must be nonzero");
 162   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive

 163   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 164   thread->set_vm_result(obj);
 165 JRT_END
 166 
 167 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array(JavaThread* thread, oopDesc* element_mirror, jint length))

 168   oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
 169   thread->set_vm_result(obj);
 170 JRT_END
 171 
 172 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance(JavaThread* thread, oopDesc* type_mirror))
 173   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(type_mirror));
 174 
 175   if (klass == NULL) {
 176     ResourceMark rm(THREAD);
 177     THROW(vmSymbols::java_lang_InstantiationException());
 178   }

 179 
 180   // Create new instance (the receiver)
 181   klass->check_valid_for_instantiation(false, CHECK);
 182 







 183   // Make sure klass gets initialized
 184   klass->initialize(CHECK);

 185 
 186   oop obj = klass->allocate_instance(CHECK);
 187   thread->set_vm_result(obj);
 188 JRT_END
 189 
 190 extern void vm_exit(int code);
 191 
 192 // Enter this method from compiled code handler below. This is where we transition
 193 // to VM mode. This is done as a helper routine so that the method called directly
 194 // from compiled code does not have to transition to VM. This allows the entry
 195 // method to see if the nmethod that we have just looked up a handler for has
 196 // been deoptimized while we were in the vm. This simplifies the assembly code
 197 // cpu directories.
 198 //
 199 // We are entering here from exception stub (via the entry method below)
 200 // If there is a compiled exception handler in this method, we will continue there;
 201 // otherwise we will unwind the stack and continue at the caller of top frame method
 202 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to
 203 // control the area where we can allow a safepoint. After we exit the safepoint area we can
 204 // check to see if the handler we are going to return is now in a nmethod that has




  92   JavaThread* thread = JavaThread::current();
  93   RegisterMap reg_map(thread, false);
  94   frame runtime_frame = thread->last_frame();
  95   frame caller_frame = runtime_frame.sender(&reg_map);
  96   assert(caller_frame.is_compiled_frame(), "must be compiled");
  97   return caller_frame.is_deoptimized_frame();
  98 }
  99 
 100 // Stress deoptimization
 101 static void deopt_caller() {
 102   if ( !caller_is_deopted()) {
 103     JavaThread* thread = JavaThread::current();
 104     RegisterMap reg_map(thread, false);
 105     frame runtime_frame = thread->last_frame();
 106     frame caller_frame = runtime_frame.sender(&reg_map);
 107     Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
 108     assert(caller_is_deopted(), "Must be deoptimized");
 109   }
 110 }
 111 
 112 // Manages a scope in which a failed heap allocation will throw an exception.
 113 // The pending exception is cleared when leaving the scope.
 114 class RetryableAllocationMark: public StackObj {
 115  private:
 116   JavaThread* _thread;
 117  public:
 118   RetryableAllocationMark(JavaThread* thread, bool activate) {
 119     if (activate) {
 120       assert(thread->in_retryable_allocation(), "retryable allocation scope is non-reentrant");
 121       _thread = thread;
 122       _thread->set_in_retryable_allocation(true);
 123     } else {
 124       _thread = NULL;
 125     }
 126   }
 127   ~RetryableAllocationMark() {
 128     if (_thread != NULL) {
 129       _thread->set_in_retryable_allocation(false);
 130       JavaThread* THREAD = _thread;
 131       if (HAS_PENDING_EXCEPTION) {
 132         oop ex = PENDING_EXCEPTION;
 133         CLEAR_PENDING_EXCEPTION;
 134         oop retry_oome = Universe::out_of_memory_error_retry();
 135         if (ex->is_a(retry_oome->klass()) && retry_oome != ex) {
 136           ResourceMark rm;
 137           fatal("Unexpected exception in scope of retryable allocation: " INTPTR_FORMAT " of type %s", p2i(ex), ex->klass()->external_name());
 138         }
 139       }
 140     }
 141   }
 142 };
 143 
 144 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance_common(JavaThread* thread, Klass* klass, bool null_on_fail))
 145   JRT_BLOCK;
 146   assert(klass->is_klass(), "not a class");
 147   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 148   InstanceKlass* ik = InstanceKlass::cast(klass);
 149   {
 150     RetryableAllocationMark ram(thread, null_on_fail);
 151     ik->check_valid_for_instantiation(true, CHECK);
 152     oop obj;
 153     if (null_on_fail) {
 154       if (!ik->is_initialized()) {
 155         // Cannot re-execute class initialization without side effects
 156         // so return without attempting the initialization
 157         return;
 158       }
 159     } else {
 160       // make sure klass is initialized
 161       ik->initialize(CHECK);
 162     }
 163     // allocate instance and return via TLS
 164     obj = ik->allocate_instance(CHECK);
 165     thread->set_vm_result(obj);
 166   }
 167   JRT_BLOCK_END;
 168   SharedRuntime::on_slowpath_allocation_exit(thread);
 169 JRT_END
 170 
 171 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array_common(JavaThread* thread, Klass* array_klass, jint length, bool null_on_fail))
 172   JRT_BLOCK;
 173   // Note: no handle for klass needed since they are not used
 174   //       anymore after new_objArray() and no GC can happen before.
 175   //       (This may have to change if this code changes!)
 176   assert(array_klass->is_klass(), "not a class");
 177   oop obj;
 178   if (array_klass->is_typeArray_klass()) {
 179     BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type();
 180     RetryableAllocationMark ram(thread, null_on_fail);
 181     obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 182   } else {
 183     Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
 184     Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
 185     RetryableAllocationMark ram(thread, null_on_fail);
 186     obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 187   }
 188   thread->set_vm_result(obj);
 189   // This is pretty rare but this runtime patch is stressful to deoptimization
 190   // if we deoptimize here so force a deopt to stress the path.
 191   if (DeoptimizeALot) {
 192     static int deopts = 0;
 193     // Alternate between deoptimizing and raising an error (which will also cause a deopt)
 194     if (deopts++ % 2 == 0) {
 195       if (null_on_fail) {
 196         return;
 197       } else {
 198         ResourceMark rm(THREAD);
 199         THROW(vmSymbols::java_lang_OutOfMemoryError());
 200       }
 201     } else {
 202       deopt_caller();
 203     }
 204   }
 205   JRT_BLOCK_END;
 206   SharedRuntime::on_slowpath_allocation_exit(thread);
 207 JRT_END
 208 
 209 JRT_ENTRY(void, JVMCIRuntime::new_multi_array_common(JavaThread* thread, Klass* klass, int rank, jint* dims, bool null_on_fail))
 210   assert(klass->is_klass(), "not a class");
 211   assert(rank >= 1, "rank must be nonzero");
 212   Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 213   RetryableAllocationMark ram(thread, null_on_fail);
 214   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 215   thread->set_vm_result(obj);
 216 JRT_END
 217 
 218 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array_common(JavaThread* thread, oopDesc* element_mirror, jint length, bool null_on_fail))
 219   RetryableAllocationMark ram(thread, null_on_fail);
 220   oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
 221   thread->set_vm_result(obj);
 222 JRT_END
 223 
 224 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance_common(JavaThread* thread, oopDesc* type_mirror, bool null_on_fail))
 225   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(type_mirror));
 226 
 227   if (klass == NULL) {
 228     ResourceMark rm(THREAD);
 229     THROW(vmSymbols::java_lang_InstantiationException());
 230   }
 231   RetryableAllocationMark ram(thread, null_on_fail);
 232 
 233   // Create new instance (the receiver)
 234   klass->check_valid_for_instantiation(false, CHECK);
 235 
 236   if (null_on_fail) {
 237     if (!klass->is_initialized()) {
 238       // Cannot re-execute class initialization without side effects
 239       // so return without attempting the initialization
 240       return;
 241     }
 242   } else {
 243     // Make sure klass gets initialized
 244     klass->initialize(CHECK);
 245   }
 246 
 247   oop obj = klass->allocate_instance(CHECK);
 248   thread->set_vm_result(obj);
 249 JRT_END
 250 
 251 extern void vm_exit(int code);
 252 
 253 // Enter this method from compiled code handler below. This is where we transition
 254 // to VM mode. This is done as a helper routine so that the method called directly
 255 // from compiled code does not have to transition to VM. This allows the entry
 256 // method to see if the nmethod that we have just looked up a handler for has
 257 // been deoptimized while we were in the vm. This simplifies the assembly code
 258 // cpu directories.
 259 //
 260 // We are entering here from exception stub (via the entry method below)
 261 // If there is a compiled exception handler in this method, we will continue there;
 262 // otherwise we will unwind the stack and continue at the caller of top frame method
 263 // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to
 264 // control the area where we can allow a safepoint. After we exit the safepoint area we can
 265 // check to see if the handler we are going to return is now in a nmethod that has


< prev index next >