changeset 3670:f198b24093f3

put back in thread transitions.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 18 Nov 2011 16:23:26 +0100
parents 53636e2c9d03
children 415aa4a73b95
files src/share/vm/ci/ciObjectFactory.cpp src/share/vm/ci/ciSymbol.hpp src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCodeInstaller.hpp src/share/vm/graal/graalEnv.cpp src/share/vm/graal/graalEnv.hpp src/share/vm/graal/graalVMEntries.cpp src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/instanceKlass.hpp
diffstat 9 files changed, 94 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/ci/ciObjectFactory.cpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/ci/ciObjectFactory.cpp	Fri Nov 18 16:23:26 2011 +0100
@@ -227,7 +227,7 @@
     return result;
   }*/
 
-  assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
+  //assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
   ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID);
   _symbols->push(s);
   return s;
--- a/src/share/vm/ci/ciSymbol.hpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/ci/ciSymbol.hpp	Fri Nov 18 16:23:26 2011 +0100
@@ -48,7 +48,7 @@
 
 private:
   const vmSymbols::SID _sid;
-  DEBUG_ONLY( bool sid_ok() { return vmSymbols::find_sid(get_symbol()) == _sid; } )
+  DEBUG_ONLY( bool sid_ok() { return true;/*vmSymbols::find_sid(get_symbol()) == _sid;*/ } )
 
   ciSymbol(Symbol* s);  // normal case, for symbols not mentioned in vmSymbols
   ciSymbol(Symbol* s, vmSymbols::SID sid);   // for use with vmSymbols
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Fri Nov 18 16:23:26 2011 +0100
@@ -229,21 +229,23 @@
   return NULL;
 }
 
-void CodeInstaller::initialize_assumptions(Handle& target_method) {
+void CodeInstaller::initialize_assumptions(oop target_method) {
   _oop_recorder = new OopRecorder(_env->arena());
   _env->set_oop_recorder(_oop_recorder);
   _env->set_dependencies(_dependencies);
   _dependencies = new Dependencies(_env);
   Handle assumptions_handle = CiTargetMethod::assumptions(HotSpotTargetMethod::targetMethod(target_method));
   if (!assumptions_handle.is_null()) {
-    objArrayHandle assumptions = (objArrayOop)CiAssumptions::list(assumptions_handle());
-    for (int i = 0; i < assumptions->length(); ++i) {
-      Handle assumption = assumptions->obj_at(i);
-      if (!assumption.is_null()) {
-        if (assumption->is_a(CiAssumptions_ConcreteSubtype::klass())) {
-          assumption_ConcreteSubtype(assumption);
-        } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) {
-          assumption_ConcreteMethod(assumption);
+    objArrayHandle assumptions(Thread::current(), (objArrayOop)CiAssumptions::list(assumptions_handle()));
+    int length = assumptions->length();
+    jobject assumptions_handle = JNIHandles::make_local(assumptions());
+    for (int i = 0; i < length; ++i) {
+      oop assumption = assumptions->obj_at(i);
+      if (assumption != NULL) {
+        if (assumption->klass() == CiAssumptions_ConcreteSubtype::klass()) {
+          assumption_ConcreteSubtype(JNIHandles::make_local(assumption));
+        } else if (assumption->klass() == CiAssumptions_ConcreteMethod::klass()) {
+          assumption_ConcreteMethod(JNIHandles::make_local(assumption));
         } else {
           assumption->print();
           fatal("unexpected Assumption subclass");
@@ -258,17 +260,18 @@
   _env = CURRENT_ENV;
   GraalCompiler::initialize_buffer_blob();
   CodeBuffer buffer(JavaThread::current()->get_buffer_blob());
-  initialize_assumptions(target_method);
+  jobject target_method_obj = JNIHandles::make_local(target_method());
+  initialize_assumptions(JNIHandles::resolve(target_method_obj));
 
   {
     No_Safepoint_Verifier no_safepoint;
-    initialize_fields(target_method);
+    initialize_fields(JNIHandles::resolve(target_method_obj));
     initialize_buffer(buffer);
     process_exception_handlers();
   }
 
   int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer
-  methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(target_method)); 
+  methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(JNIHandles::resolve(target_method_obj))); 
   {
     nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table,
       &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, false, install_code);
@@ -283,7 +286,7 @@
   
   _oop_recorder = new OopRecorder(_env->arena());
   _env->set_oop_recorder(_oop_recorder);
-  initialize_fields(target_method);
+  initialize_fields(target_method());
   assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method");
 
   // (very) conservative estimate: each site needs a relocation
@@ -297,7 +300,7 @@
   id = VmIds::addStub(blob->code_begin());
 }
 
-void CodeInstaller::initialize_fields(Handle& target_method) {
+void CodeInstaller::initialize_fields(oop target_method) {
   _citarget_method = HotSpotTargetMethod::targetMethod(target_method);
   _hotspot_method = HotSpotTargetMethod::method(target_method);
   if (_hotspot_method != NULL) {
@@ -364,30 +367,46 @@
   }
 }
 
-void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) {
-  Handle context_handle = CiAssumptions_ConcreteSubtype::context(assumption);
-  Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(assumption);
+void CodeInstaller::assumption_ConcreteSubtype(jobject assumption) {
+  Handle context_handle = CiAssumptions_ConcreteSubtype::context(JNIHandles::resolve(assumption));
+  ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle)));
 
-  ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle)));
+  Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(JNIHandles::resolve(assumption));
   ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_handle)));
 
   _dependencies->assert_leaf_type(type);
-  if (context != type) {
+  if (context != type) {
+    // Once you removed the transition to native here
+    // and have realized what a terrible mistake that was,
+    // please increment the following counter as a warning
+    // to the next guy:
+    //
+    // total_hours_wasted_here = 8
+    ThreadToNativeFromVM trans(JavaThread::current());
     assert(context->is_abstract(), "");
     _dependencies->assert_abstract_with_unique_concrete_subtype(context, type);
   }
 }
 
-void CodeInstaller::assumption_ConcreteMethod(Handle assumption) {
-  Handle context_handle = CiAssumptions_ConcreteMethod::context(assumption);
-  Handle method_handle = CiAssumptions_ConcreteMethod::method(assumption);
+void CodeInstaller::assumption_ConcreteMethod(jobject assumption) {
+  Handle method_handle = CiAssumptions_ConcreteMethod::method(JNIHandles::resolve(assumption));
   methodHandle method = getMethodFromHotSpotMethod(method_handle());
+  ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method());
+  
+  Handle context_handle = CiAssumptions_ConcreteMethod::context(JNIHandles::resolve(assumption));
   methodHandle context = getMethodFromHotSpotMethod(context_handle());
-
-  ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method());
   ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context());
   ciKlass* context_klass = c->holder();
-  _dependencies->assert_unique_concrete_method(context_klass, m);
+  {
+    // Once you removed the transition to native here
+    // and have realized what a terrible mistake that was,
+    // please increment the following counter as a warning
+    // to the next guy:
+    //
+    // total_hours_wasted_here = 8
+    ThreadToNativeFromVM trans(JavaThread::current());
+    _dependencies->assert_unique_concrete_method(context_klass, m);
+  }
 }
 
 void CodeInstaller::process_exception_handlers() {
--- a/src/share/vm/graal/graalCodeInstaller.hpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/graal/graalCodeInstaller.hpp	Fri Nov 18 16:23:26 2011 +0100
@@ -91,14 +91,14 @@
 
 private:
   // extract the fields of the CiTargetMethod
-  void initialize_fields(Handle& target_method);
-  void initialize_assumptions(Handle& target_method);
+  void initialize_fields(oop target_method);
+  void initialize_assumptions(oop target_method);
 
   // perform data and call relocation on the CodeBuffer
   void initialize_buffer(CodeBuffer& buffer);
 
-  void assumption_ConcreteSubtype(Handle assumption);
-  void assumption_ConcreteMethod(Handle assumption);
+  void assumption_ConcreteSubtype(jobject assumption);
+  void assumption_ConcreteMethod(jobject assumption);
 
   void site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site);
   void site_Call(CodeBuffer& buffer, jint pc_offset, oop site);
--- a/src/share/vm/graal/graalEnv.cpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/graal/graalEnv.cpp	Fri Nov 18 16:23:26 2011 +0100
@@ -49,7 +49,7 @@
 //
 // Note: the logic of this method should mirror the logic of
 // constantPoolOopDesc::verify_constant_pool_resolve.
-bool GraalEnv::check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klass) {
+bool GraalEnv::check_klass_accessibility(KlassHandle& accessing_klass, KlassHandle& resolved_klass) {
   if (accessing_klass->oop_is_objArray()) {
     accessing_klass = objArrayKlass::cast(accessing_klass())->bottom_klass();
   }
@@ -69,8 +69,8 @@
 
 // ------------------------------------------------------------------
 // ciEnv::get_klass_by_name_impl
-KlassHandle GraalEnv::get_klass_by_name_impl(KlassHandle accessing_klass,
-                                          constantPoolHandle cpool,
+KlassHandle GraalEnv::get_klass_by_name_impl(KlassHandle& accessing_klass,
+                                          constantPoolHandle& cpool,
                                           Symbol* sym,
                                           bool require_local) {
   EXCEPTION_CONTEXT;
@@ -149,7 +149,7 @@
 
 // ------------------------------------------------------------------
 // ciEnv::get_klass_by_name
-KlassHandle GraalEnv::get_klass_by_name(KlassHandle accessing_klass,
+KlassHandle GraalEnv::get_klass_by_name(KlassHandle& accessing_klass,
                                   Symbol* klass_name,
                                   bool require_local) {
   ResourceMark rm;
@@ -163,10 +163,10 @@
 // ciEnv::get_klass_by_index_impl
 //
 // Implementation of get_klass_by_index.
-KlassHandle GraalEnv::get_klass_by_index_impl(constantPoolHandle cpool,
+KlassHandle GraalEnv::get_klass_by_index_impl(constantPoolHandle& cpool,
                                         int index,
                                         bool& is_accessible,
-                                        KlassHandle accessor) {
+                                        KlassHandle& accessor) {
   EXCEPTION_CONTEXT;
   KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
   Symbol* klass_name = NULL;
@@ -207,7 +207,7 @@
       is_accessible = false;
     } else {
       // Linked locally, and we must also check public/private, etc.
-      is_accessible = check_klass_accessibility(accessor(), k());
+      is_accessible = check_klass_accessibility(accessor, k);
     }
     return k;
   }
@@ -221,10 +221,10 @@
 // ciEnv::get_klass_by_index
 //
 // Get a klass from the constant pool.
-KlassHandle GraalEnv::get_klass_by_index(constantPoolHandle cpool,
+KlassHandle GraalEnv::get_klass_by_index(constantPoolHandle& cpool,
                                    int index,
                                    bool& is_accessible,
-                                   KlassHandle accessor) {
+                                   KlassHandle& accessor) {
   ResourceMark rm;
   return get_klass_by_index_impl(cpool, index, is_accessible, accessor);
 }
@@ -236,7 +236,7 @@
 //
 // Implementation note: the results of field lookups are cached
 // in the accessor klass.
-void GraalEnv::get_field_by_index_impl(instanceKlassHandle klass, fieldDescriptor& field_desc,
+void GraalEnv::get_field_by_index_impl(instanceKlassHandle& klass, fieldDescriptor& field_desc,
                                         int index) {
   EXCEPTION_CONTEXT;
 
@@ -282,7 +282,7 @@
 // ciEnv::get_field_by_index
 //
 // Get a field by index from a klass's constant pool.
-void GraalEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd,
+void GraalEnv::get_field_by_index(instanceKlassHandle& accessor, fieldDescriptor& fd,
                                    int index) {
   ResourceMark rm;
   return get_field_by_index_impl(accessor, fd, index);
@@ -293,8 +293,8 @@
 //
 // Perform an appropriate method lookup based on accessor, holder,
 // name, signature, and bytecode.
-methodHandle GraalEnv::lookup_method(instanceKlassHandle  h_accessor,
-                               instanceKlassHandle  h_holder,
+methodHandle GraalEnv::lookup_method(instanceKlassHandle& h_accessor,
+                               instanceKlassHandle& h_holder,
                                Symbol*       name,
                                Symbol*       sig,
                                Bytecodes::Code bc) {
@@ -329,9 +329,9 @@
 
 // ------------------------------------------------------------------
 // ciEnv::get_method_by_index_impl
-methodHandle GraalEnv::get_method_by_index_impl(constantPoolHandle cpool,
+methodHandle GraalEnv::get_method_by_index_impl(constantPoolHandle& cpool,
                                           int index, Bytecodes::Code bc,
-                                          instanceKlassHandle accessor) {
+                                          instanceKlassHandle& accessor) {
   int holder_index = cpool->klass_ref_index_at(index);
   bool holder_is_accessible;
   KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
@@ -364,7 +364,7 @@
 
 // ------------------------------------------------------------------
 // ciEnv::get_instance_klass_for_declared_method_holder
-instanceKlassHandle GraalEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
+instanceKlassHandle GraalEnv::get_instance_klass_for_declared_method_holder(KlassHandle& method_holder) {
   // For the case of <array>.clone(), the method holder can be a ciArrayKlass
   // instead of a ciInstanceKlass.  For that case simply pretend that the
   // declared holder is Object.clone since that's where the call will bottom out.
@@ -386,9 +386,9 @@
 
 // ------------------------------------------------------------------
 // ciEnv::get_method_by_index
-methodHandle GraalEnv::get_method_by_index(constantPoolHandle cpool,
+methodHandle GraalEnv::get_method_by_index(constantPoolHandle& cpool,
                                      int index, Bytecodes::Code bc,
-                                     instanceKlassHandle accessor) {
+                                     instanceKlassHandle& accessor) {
   ResourceMark rm;
   assert(bc != Bytecodes::_invokedynamic, "invokedynamic not yet supported");
   return get_method_by_index_impl(cpool, index, bc, accessor);
--- a/src/share/vm/graal/graalEnv.hpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/graal/graalEnv.hpp	Fri Nov 18 16:23:26 2011 +0100
@@ -58,42 +58,42 @@
   // The CI treats a klass as loaded if it is consistently defined in
   // another loader, even if it hasn't yet been loaded in all loaders
   // that could potentially see it via delegation.
-  static KlassHandle get_klass_by_name(KlassHandle accessing_klass,
+  static KlassHandle get_klass_by_name(KlassHandle& accessing_klass,
                              Symbol* klass_name,
                              bool require_local);
 
   // Constant pool access.
-  static KlassHandle   get_klass_by_index(constantPoolHandle cpool,
+  static KlassHandle   get_klass_by_index(constantPoolHandle& cpool,
                                 int klass_index,
                                 bool& is_accessible,
-                                KlassHandle loading_klass);
-  static void   get_field_by_index(instanceKlassHandle loading_klass, fieldDescriptor& fd,
+                                KlassHandle& loading_klass);
+  static void   get_field_by_index(instanceKlassHandle& loading_klass, fieldDescriptor& fd,
                                 int field_index);
-  static methodHandle  get_method_by_index(constantPoolHandle cpool,
+  static methodHandle  get_method_by_index(constantPoolHandle& cpool,
                                  int method_index, Bytecodes::Code bc,
-                                 instanceKlassHandle loading_klass);
+                                 instanceKlassHandle& loading_klass);
 
 private:
 
   // Implementation methods for loading and constant pool access.
-  static KlassHandle get_klass_by_name_impl(KlassHandle accessing_klass,
-                                  constantPoolHandle cpool,
+  static KlassHandle get_klass_by_name_impl(KlassHandle& accessing_klass,
+                                  constantPoolHandle& cpool,
                                   Symbol* klass_name,
                                   bool require_local);
-  static KlassHandle   get_klass_by_index_impl(constantPoolHandle cpool,
+  static KlassHandle   get_klass_by_index_impl(constantPoolHandle& cpool,
                                      int klass_index,
                                      bool& is_accessible,
-                                     KlassHandle loading_klass);
-  static void   get_field_by_index_impl(instanceKlassHandle loading_klass, fieldDescriptor& fd,
+                                     KlassHandle& loading_klass);
+  static void   get_field_by_index_impl(instanceKlassHandle& loading_klass, fieldDescriptor& fd,
                                      int field_index);
-  static methodHandle  get_method_by_index_impl(constantPoolHandle cpool,
+  static methodHandle  get_method_by_index_impl(constantPoolHandle& cpool,
                                       int method_index, Bytecodes::Code bc,
-                                      instanceKlassHandle loading_klass);
+                                      instanceKlassHandle& loading_klass);
 
   // Helper methods
-  static bool       check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klassOop);
-  static methodHandle  lookup_method(instanceKlassHandle  accessor,
-                           instanceKlassHandle  holder,
+  static bool       check_klass_accessibility(KlassHandle& accessing_klass, KlassHandle& resolved_klassOop);
+  static methodHandle  lookup_method(instanceKlassHandle&  accessor,
+                           instanceKlassHandle&  holder,
                            Symbol*         name,
                            Symbol*         sig,
                            Bytecodes::Code bc);
@@ -135,7 +135,7 @@
   // ciInstanceKlass*.  This is needed since the holder of a method in
   // the bytecodes could be an array type.  Basically this converts
   // array types into java/lang/Object and other types stay as they are.
-  static instanceKlassHandle get_instance_klass_for_declared_method_holder(KlassHandle klass);
+  static instanceKlassHandle get_instance_klass_for_declared_method_holder(KlassHandle& klass);
 };
 
 #endif // SHARE_VM_GRAAL_GRAALENV_HPP
--- a/src/share/vm/graal/graalVMEntries.cpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/graal/graalVMEntries.cpp	Fri Nov 18 16:23:26 2011 +0100
@@ -467,9 +467,10 @@
   VM_ENTRY_MARK;
   index = GraalCompiler::to_cp_index_u2(index);
   constantPoolHandle cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants();
+  instanceKlassHandle pool_holder(cp->pool_holder());
 
   Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF);
-  methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, cp->pool_holder());
+  methodHandle method = GraalEnv::get_method_by_index(cp, index, bc, pool_holder);
   if (!method.is_null()) {
     Handle ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL);
     return JNIHandles::make_local(THREAD, ret());
@@ -926,6 +927,7 @@
 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code) {
   VM_ENTRY_MARK;
   ResourceMark rm;
+  HandleMark hm;
   Handle targetMethodHandle = JNIHandles::resolve(targetMethod);
   nmethod* nm = NULL;
   Arena arena;
@@ -938,6 +940,7 @@
 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_VMEntries_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) {
   VM_ENTRY_MARK;
   ResourceMark rm;
+  HandleMark hm;
   Handle targetMethodHandle = JNIHandles::resolve(targetMethod);
   jlong id;
   Arena arena;
--- a/src/share/vm/oops/instanceKlass.cpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/oops/instanceKlass.cpp	Fri Nov 18 16:23:26 2011 +0100
@@ -2280,7 +2280,7 @@
 }
 
 // -----------------------------------------------------------------------------------------------------
-#ifndef PRODUCT
+
 
 // Printing
 
@@ -2350,7 +2350,7 @@
   }
 }
 
-#endif //PRODUCT
+
 
 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) {
   st->print("a ");
--- a/src/share/vm/oops/instanceKlass.hpp	Fri Nov 18 14:14:37 2011 +0100
+++ b/src/share/vm/oops/instanceKlass.hpp	Fri Nov 18 16:23:26 2011 +0100
@@ -98,7 +98,7 @@
   virtual void do_field(fieldDescriptor* fd) = 0;
 };
 
-#ifndef PRODUCT
+//#ifndef PRODUCT
 // Print fields.
 // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
 class FieldPrinter: public FieldClosure {
@@ -108,7 +108,7 @@
    FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {}
    void do_field(fieldDescriptor* fd);
 };
-#endif  // !PRODUCT
+//#endif  // !PRODUCT
 
 // ValueObjs embedded in klass. Describes where oops are located in instances of
 // this klass.
@@ -832,12 +832,11 @@
  public:
   // Printing
   void oop_print_value_on(oop obj, outputStream* st);
-#ifndef PRODUCT
+
   void oop_print_on      (oop obj, outputStream* st);
 
   void print_dependent_nmethods(bool verbose = false);
   bool is_dependent_nmethod(nmethod* nm);
-#endif
 
   // Verification
   const char* internal_name() const;