< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

        

@@ -158,11 +158,10 @@
   compute_offset(dest_offset, ik, name, signature_symbol, is_static);
 }
 
 int java_lang_String::value_offset  = 0;
 int java_lang_String::hash_offset   = 0;
-int java_lang_String::hashIsZero_offset = 0;
 int java_lang_String::coder_offset  = 0;
 
 bool java_lang_String::initialized  = false;
 
 bool java_lang_String::is_instance(oop obj) {

@@ -178,12 +177,11 @@
   compute_offset(offset, klass, name, vmSymbols::signature(), is_static)
 
 #define STRING_FIELDS_DO(macro) \
   macro(value_offset, k, vmSymbols::value_name(), byte_array_signature, false); \
   macro(hash_offset,  k, "hash",                  int_signature,        false); \
-  macro(hashIsZero_offset, k, "hashIsZero",       bool_signature,       false); \
-  macro(coder_offset, k, "coder",                 byte_signature,       false);
+  macro(coder_offset, k, "coder",                 byte_signature,       false)
 
 void java_lang_String::compute_offsets() {
   if (initialized) {
     return;
   }

@@ -218,11 +216,11 @@
   }
 };
 
 void java_lang_String::set_compact_strings(bool value) {
   CompactStringsFixup fix(value);
-  SystemDictionary::String_klass()->do_local_static_fields(&fix);
+  InstanceKlass::cast(SystemDictionary::String_klass())->do_local_static_fields(&fix);
 }
 
 Handle java_lang_String::basic_create(int length, bool is_latin1, TRAPS) {
   assert(initialized, "Must be initialized");
   assert(CompactStrings || !is_latin1, "Must be UTF16 without CompactStrings");

@@ -507,42 +505,22 @@
   }
   return result;
 }
 
 unsigned int java_lang_String::hash_code(oop java_string) {
-  // The hash and hashIsZero fields are subject to a benign data race,
-  // making it crucial to ensure that any observable result of the
-  // calculation in this method stays correct under any possible read of
-  // these fields. Necessary restrictions to allow this to be correct
-  // without explicit memory fences or similar concurrency primitives is
-  // that we can ever only write to one of these two fields for a given
-  // String instance, and that the computation is idempotent and derived
-  // from immutable state
-  assert(initialized && (hash_offset > 0) && (hashIsZero_offset > 0), "Must be initialized");
-  if (java_lang_String::hash_is_set(java_string)) {
-    return java_string->int_field(hash_offset);
-  }
-
-  typeArrayOop value = java_lang_String::value(java_string);
-  int         length = java_lang_String::length(java_string, value);
-  bool     is_latin1 = java_lang_String::is_latin1(java_string);
+  typeArrayOop value  = java_lang_String::value(java_string);
+  int          length = java_lang_String::length(java_string, value);
+  // Zero length string will hash to zero with String.hashCode() function.
+  if (length == 0) return 0;
 
-  unsigned int hash = 0;
-  if (length > 0) {
-    if (is_latin1) {
-      hash = java_lang_String::hash_code(value->byte_at_addr(0), length);
-    } else {
-      hash = java_lang_String::hash_code(value->char_at_addr(0), length);
-    }
-  }
+  bool      is_latin1 = java_lang_String::is_latin1(java_string);
 
-  if (hash != 0) {
-    java_string->int_field_put(hash_offset, hash);
+  if (is_latin1) {
+    return java_lang_String::hash_code(value->byte_at_addr(0), length);
   } else {
-    java_string->bool_field_put(hashIsZero_offset, true);
+    return java_lang_String::hash_code(value->char_at_addr(0), length);
   }
-  return hash;
 }
 
 char* java_lang_String::as_quoted_ascii(oop java_string) {
   typeArrayOop value  = java_lang_String::value(java_string);
   int          length = java_lang_String::length(java_string, value);

@@ -1712,51 +1690,89 @@
   return java_thread->obj_field(_inheritedAccessControlContext_offset);
 }
 
 
 jlong java_lang_Thread::stackSize(oop java_thread) {
-  return java_thread->long_field(_stackSize_offset);
+  if (_stackSize_offset > 0) {
+    return java_thread->long_field(_stackSize_offset);
+  } else {
+    return 0;
+  }
 }
 
 // Write the thread status value to threadStatus field in java.lang.Thread java class.
 void java_lang_Thread::set_thread_status(oop java_thread,
                                          java_lang_Thread::ThreadStatus status) {
-  java_thread->int_field_put(_thread_status_offset, status);
+  // The threadStatus is only present starting in 1.5
+  if (_thread_status_offset > 0) {
+    java_thread->int_field_put(_thread_status_offset, status);
+  }
 }
 
 // Read thread status value from threadStatus field in java.lang.Thread java class.
 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) {
   // Make sure the caller is operating on behalf of the VM or is
   // running VM code (state == _thread_in_vm).
   assert(Threads_lock->owned_by_self() || Thread::current()->is_VM_thread() ||
          JavaThread::current()->thread_state() == _thread_in_vm,
          "Java Thread is not running in vm");
-  return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
+  // The threadStatus is only present starting in 1.5
+  if (_thread_status_offset > 0) {
+    return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
+  } else {
+    // All we can easily figure out is if it is alive, but that is
+    // enough info for a valid unknown status.
+    // These aren't restricted to valid set ThreadStatus values, so
+    // use JVMTI values and cast.
+    JavaThread* thr = java_lang_Thread::thread(java_thread);
+    if (thr == NULL) {
+      // the thread hasn't run yet or is in the process of exiting
+      return NEW;
+    }
+    return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE;
+  }
 }
 
 
 jlong java_lang_Thread::thread_id(oop java_thread) {
-  return java_thread->long_field(_tid_offset);
+  // The thread ID field is only present starting in 1.5
+  if (_tid_offset > 0) {
+    return java_thread->long_field(_tid_offset);
+  } else {
+    return 0;
+  }
 }
 
 oop java_lang_Thread::park_blocker(oop java_thread) {
-  assert(JDK_Version::current().supports_thread_park_blocker(),
-         "Must support parkBlocker field");
+  assert(JDK_Version::current().supports_thread_park_blocker() &&
+         _park_blocker_offset != 0, "Must support parkBlocker field");
+
+  if (_park_blocker_offset > 0) {
+    return java_thread->obj_field(_park_blocker_offset);
+  }
 
-  return java_thread->obj_field(_park_blocker_offset);
+  return NULL;
 }
 
 jlong java_lang_Thread::park_event(oop java_thread) {
-  return java_thread->long_field(_park_event_offset);
+  if (_park_event_offset > 0) {
+    return java_thread->long_field(_park_event_offset);
+  }
+  return 0;
 }
 
 bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) {
-  java_thread->long_field_put(_park_event_offset, ptr);
-  return true;
+  if (_park_event_offset > 0) {
+    java_thread->long_field_put(_park_event_offset, ptr);
+    return true;
+  }
+  return false;
 }
 
+
 const char* java_lang_Thread::thread_status_name(oop java_thread) {
+  assert(_thread_status_offset != 0, "Must have thread status");
   ThreadStatus status = (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset);
   switch (status) {
     case NEW                      : return "NEW";
     case RUNNABLE                 : return "RUNNABLE";
     case SLEEPING                 : return "TIMED_WAITING (sleeping)";

@@ -3595,52 +3611,27 @@
 void java_lang_invoke_ResolvedMethodName::set_vmtarget(oop resolved_method, Method* m) {
   assert(is_instance(resolved_method), "wrong type");
   resolved_method->address_field_put(_vmtarget_offset, (address)m);
 }
 
-void java_lang_invoke_ResolvedMethodName::set_vmholder(oop resolved_method, oop holder) {
-  assert(is_instance(resolved_method), "wrong type");
-  resolved_method->obj_field_put(_vmholder_offset, holder);
-}
-
 oop java_lang_invoke_ResolvedMethodName::find_resolved_method(const methodHandle& m, TRAPS) {
-  const Method* method = m();
-
   // lookup ResolvedMethod oop in the table, or create a new one and intern it
-  oop resolved_method = ResolvedMethodTable::find_method(method);
-  if (resolved_method != NULL) {
-    return resolved_method;
-  }
-
-  InstanceKlass* k = SystemDictionary::ResolvedMethodName_klass();
-  if (!k->is_initialized()) {
-    k->initialize(CHECK_NULL);
+  oop resolved_method = ResolvedMethodTable::find_method(m());
+  if (resolved_method == NULL) {
+    InstanceKlass* k = SystemDictionary::ResolvedMethodName_klass();
+    if (!k->is_initialized()) {
+      k->initialize(CHECK_NULL);
+    }
+    oop new_resolved_method = k->allocate_instance(CHECK_NULL);
+    new_resolved_method->address_field_put(_vmtarget_offset, (address)m());
+    // Add a reference to the loader (actually mirror because unsafe anonymous classes will not have
+    // distinct loaders) to ensure the metadata is kept alive.
+    // This mirror may be different than the one in clazz field.
+    new_resolved_method->obj_field_put(_vmholder_offset, m->method_holder()->java_mirror());
+    resolved_method = ResolvedMethodTable::add_method(m, Handle(THREAD, new_resolved_method));
   }
-
-  oop new_resolved_method = k->allocate_instance(CHECK_NULL);
-
-  NoSafepointVerifier nsv;
-
-  if (method->is_old()) {
-    method = (method->is_deleted()) ? Universe::throw_no_such_method_error() :
-                                      method->get_new_method();
-  }
-
-  InstanceKlass* holder = method->method_holder();
-
-  set_vmtarget(new_resolved_method, const_cast<Method*>(method));
-  // Add a reference to the loader (actually mirror because unsafe anonymous classes will not have
-  // distinct loaders) to ensure the metadata is kept alive.
-  // This mirror may be different than the one in clazz field.
-  set_vmholder(new_resolved_method, holder->java_mirror());
-
-  // Set flag in class to indicate this InstanceKlass has entries in the table
-  // to avoid walking table during redefinition if none of the redefined classes
-  // have any membernames in the table.
-  holder->set_has_resolved_methods();
-
-  return ResolvedMethodTable::add_method(method, Handle(THREAD, new_resolved_method));
+  return resolved_method;
 }
 
 oop java_lang_invoke_LambdaForm::vmentry(oop lform) {
   assert(is_instance(lform), "wrong type");
   return lform->obj_field(_vmentry_offset);

@@ -3998,52 +3989,10 @@
 
 int java_lang_System::in_offset_in_bytes() { return static_in_offset; }
 int java_lang_System::out_offset_in_bytes() { return static_out_offset; }
 int java_lang_System::err_offset_in_bytes() { return static_err_offset; }
 
-// Support for jdk_internal_misc_UnsafeConstants
-//
-class UnsafeConstantsFixup : public FieldClosure {
-private:
-  int _address_size;
-  int _page_size;
-  bool _big_endian;
-  bool _use_unaligned_access;
-public:
-  UnsafeConstantsFixup() {
-    // round up values for all static final fields
-    _address_size = sizeof(void*);
-    _page_size = os::vm_page_size();
-    _big_endian = LITTLE_ENDIAN_ONLY(false) BIG_ENDIAN_ONLY(true);
-    _use_unaligned_access = UseUnalignedAccesses;
-  }
-
-  void do_field(fieldDescriptor* fd) {
-    oop mirror = fd->field_holder()->java_mirror();
-    assert(mirror != NULL, "UnsafeConstants must have mirror already");
-    assert(fd->field_holder() == SystemDictionary::UnsafeConstants_klass(), "Should be UnsafeConstants");
-    assert(fd->is_final(), "fields of UnsafeConstants must be final");
-    assert(fd->is_static(), "fields of UnsafeConstants must be static");
-    if (fd->name() == vmSymbols::address_size_name()) {
-      mirror->int_field_put(fd->offset(), _address_size);
-    } else if (fd->name() == vmSymbols::page_size_name()) {
-      mirror->int_field_put(fd->offset(), _page_size);
-    } else if (fd->name() == vmSymbols::big_endian_name()) {
-      mirror->bool_field_put(fd->offset(), _big_endian);
-    } else if (fd->name() == vmSymbols::use_unaligned_access_name()) {
-      mirror->bool_field_put(fd->offset(), _use_unaligned_access);
-    } else {
-      assert(false, "unexpected UnsafeConstants field");
-    }
-  }
-};
-
-void jdk_internal_misc_UnsafeConstants::set_unsafe_constants() {
-  UnsafeConstantsFixup fixup;
-  SystemDictionary::UnsafeConstants_klass()->do_local_static_fields(&fixup);
-}
-
 int java_lang_Class::_klass_offset;
 int java_lang_Class::_array_klass_offset;
 int java_lang_Class::_oop_size_offset;
 int java_lang_Class::_static_oop_field_count_offset;
 int java_lang_Class::_class_loader_offset;
< prev index next >