hotspot/src/share/vm/classfile/javaClasses.cpp
changeset 379 10767ca40189
parent 360 21d113ecbf6a
child 591 04d2e26e6d69
--- a/hotspot/src/share/vm/classfile/javaClasses.cpp	Tue Apr 29 19:40:51 2008 -0700
+++ b/hotspot/src/share/vm/classfile/javaClasses.cpp	Tue Apr 29 19:45:22 2008 -0700
@@ -25,25 +25,29 @@
 # include "incls/_precompiled.incl"
 # include "incls/_javaClasses.cpp.incl"
 
-// Helpful macro for computing field offsets at run time rather than hardcoding them
-#define COMPUTE_OFFSET(klass_name_as_C_str, dest_offset, klass_oop, name_symbol, signature_symbol) \
-{                                                                                                  \
-  fieldDescriptor fd;                                                                              \
-  instanceKlass* ik = instanceKlass::cast(klass_oop);                                              \
-  if (!ik->find_local_field(name_symbol, signature_symbol, &fd)) {                                 \
-    fatal("Invalid layout of " klass_name_as_C_str);                                               \
-  }                                                                                                \
-  dest_offset = fd.offset();                                                                       \
+// Helpful routine for computing field offsets at run time rather than hardcoding them
+static void
+compute_offset(int &dest_offset,
+               klassOop klass_oop, symbolOop name_symbol, symbolOop signature_symbol) {
+  fieldDescriptor fd;
+  instanceKlass* ik = instanceKlass::cast(klass_oop);
+  if (!ik->find_local_field(name_symbol, signature_symbol, &fd)) {
+    ResourceMark rm;
+    tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string());
+    fatal("Invalid layout of preloaded class");
+  }
+  dest_offset = fd.offset();
 }
 
 // Same as above but for "optional" offsets that might not be present in certain JDK versions
-#define COMPUTE_OPTIONAL_OFFSET(klass_name_as_C_str, dest_offset, klass_oop, name_symbol, signature_symbol) \
-{                                                                                                  \
-  fieldDescriptor fd;                                                                              \
-  instanceKlass* ik = instanceKlass::cast(klass_oop);                                              \
-  if (ik->find_local_field(name_symbol, signature_symbol, &fd)) {                                  \
-    dest_offset = fd.offset();                                                                     \
-  }                                                                                                \
+static void
+compute_optional_offset(int& dest_offset,
+                        klassOop klass_oop, symbolOop name_symbol, symbolOop signature_symbol) {
+  fieldDescriptor fd;
+  instanceKlass* ik = instanceKlass::cast(klass_oop);
+  if (ik->find_local_field(name_symbol, signature_symbol, &fd)) {
+    dest_offset = fd.offset();
+  }
 }
 
 Handle java_lang_String::basic_create(int length, bool tenured, TRAPS) {
@@ -445,7 +449,7 @@
   klassOop k = SystemDictionary::class_klass();
   // The classRedefinedCount field is only present starting in 1.5,
   // so don't go fatal.
-  COMPUTE_OPTIONAL_OFFSET("java.lang.Class", classRedefinedCount_offset,
+  compute_optional_offset(classRedefinedCount_offset,
     k, vmSymbols::classRedefinedCount_name(), vmSymbols::int_signature());
 }
 
@@ -499,22 +503,22 @@
   assert(_group_offset == 0, "offsets should be initialized only once");
 
   klassOop k = SystemDictionary::thread_klass();
-  COMPUTE_OFFSET("java.lang.Thread", _name_offset,      k, vmSymbols::name_name(),      vmSymbols::char_array_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _group_offset,     k, vmSymbols::group_name(),     vmSymbols::threadgroup_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), vmSymbols::classloader_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), vmSymbols::accesscontrolcontext_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _priority_offset,  k, vmSymbols::priority_name(),  vmSymbols::int_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _daemon_offset,    k, vmSymbols::daemon_name(),    vmSymbols::bool_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _eetop_offset,     k, vmSymbols::eetop_name(),     vmSymbols::long_signature());
-  COMPUTE_OFFSET("java.lang.Thread", _stillborn_offset, k, vmSymbols::stillborn_name(), vmSymbols::bool_signature());
+  compute_offset(_name_offset,      k, vmSymbols::name_name(),      vmSymbols::char_array_signature());
+  compute_offset(_group_offset,     k, vmSymbols::group_name(),     vmSymbols::threadgroup_signature());
+  compute_offset(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), vmSymbols::classloader_signature());
+  compute_offset(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), vmSymbols::accesscontrolcontext_signature());
+  compute_offset(_priority_offset,  k, vmSymbols::priority_name(),  vmSymbols::int_signature());
+  compute_offset(_daemon_offset,    k, vmSymbols::daemon_name(),    vmSymbols::bool_signature());
+  compute_offset(_eetop_offset,     k, vmSymbols::eetop_name(),     vmSymbols::long_signature());
+  compute_offset(_stillborn_offset, k, vmSymbols::stillborn_name(), vmSymbols::bool_signature());
   // The stackSize field is only present starting in 1.4, so don't go fatal.
-  COMPUTE_OPTIONAL_OFFSET("java.lang.Thread", _stackSize_offset, k, vmSymbols::stackSize_name(), vmSymbols::long_signature());
+  compute_optional_offset(_stackSize_offset, k, vmSymbols::stackSize_name(), vmSymbols::long_signature());
   // The tid and thread_status fields are only present starting in 1.5, so don't go fatal.
-  COMPUTE_OPTIONAL_OFFSET("java.lang.Thread", _tid_offset, k, vmSymbols::thread_id_name(), vmSymbols::long_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.Thread", _thread_status_offset, k, vmSymbols::thread_status_name(), vmSymbols::int_signature());
+  compute_optional_offset(_tid_offset, k, vmSymbols::thread_id_name(), vmSymbols::long_signature());
+  compute_optional_offset(_thread_status_offset, k, vmSymbols::thread_status_name(), vmSymbols::int_signature());
   // The parkBlocker field is only present starting in 1.6, so don't go fatal.
-  COMPUTE_OPTIONAL_OFFSET("java.lang.Thread", _park_blocker_offset, k, vmSymbols::park_blocker_name(), vmSymbols::object_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.Thread", _park_event_offset, k, vmSymbols::park_event_name(),
+  compute_optional_offset(_park_blocker_offset, k, vmSymbols::park_blocker_name(), vmSymbols::object_signature());
+  compute_optional_offset(_park_event_offset, k, vmSymbols::park_event_name(),
  vmSymbols::long_signature());
 }
 
@@ -759,16 +763,16 @@
 
   klassOop k = SystemDictionary::threadGroup_klass();
 
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _parent_offset,      k, vmSymbols::parent_name(),      vmSymbols::threadgroup_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _name_offset,        k, vmSymbols::name_name(),        vmSymbols::string_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _threads_offset,     k, vmSymbols::threads_name(),     vmSymbols::thread_array_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _groups_offset,      k, vmSymbols::groups_name(),      vmSymbols::threadgroup_array_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _maxPriority_offset, k, vmSymbols::maxPriority_name(), vmSymbols::int_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _destroyed_offset,   k, vmSymbols::destroyed_name(),   vmSymbols::bool_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _daemon_offset,      k, vmSymbols::daemon_name(),      vmSymbols::bool_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _vmAllowSuspension_offset, k, vmSymbols::vmAllowSuspension_name(), vmSymbols::bool_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _nthreads_offset,    k, vmSymbols::nthreads_name(),    vmSymbols::int_signature());
-  COMPUTE_OFFSET("java.lang.ThreadGroup", _ngroups_offset,     k, vmSymbols::ngroups_name(),     vmSymbols::int_signature());
+  compute_offset(_parent_offset,      k, vmSymbols::parent_name(),      vmSymbols::threadgroup_signature());
+  compute_offset(_name_offset,        k, vmSymbols::name_name(),        vmSymbols::string_signature());
+  compute_offset(_threads_offset,     k, vmSymbols::threads_name(),     vmSymbols::thread_array_signature());
+  compute_offset(_groups_offset,      k, vmSymbols::groups_name(),      vmSymbols::threadgroup_array_signature());
+  compute_offset(_maxPriority_offset, k, vmSymbols::maxPriority_name(), vmSymbols::int_signature());
+  compute_offset(_destroyed_offset,   k, vmSymbols::destroyed_name(),   vmSymbols::bool_signature());
+  compute_offset(_daemon_offset,      k, vmSymbols::daemon_name(),      vmSymbols::bool_signature());
+  compute_offset(_vmAllowSuspension_offset, k, vmSymbols::vmAllowSuspension_name(), vmSymbols::bool_signature());
+  compute_offset(_nthreads_offset,    k, vmSymbols::nthreads_name(),    vmSymbols::int_signature());
+  compute_offset(_ngroups_offset,     k, vmSymbols::ngroups_name(),     vmSymbols::int_signature());
 }
 
 oop java_lang_Throwable::backtrace(oop throwable) {
@@ -1361,6 +1365,7 @@
 
   // Allocate java.lang.StackTraceElement instance
   klassOop k = SystemDictionary::stackTraceElement_klass();
+  assert(k != NULL, "must be loaded in 1.4+");
   instanceKlassHandle ik (THREAD, k);
   if (ik->should_be_initialized()) {
     ik->initialize(CHECK_0);
@@ -1398,7 +1403,7 @@
 
 void java_lang_reflect_AccessibleObject::compute_offsets() {
   klassOop k = SystemDictionary::reflect_accessible_object_klass();
-  COMPUTE_OFFSET("java.lang.reflect.AccessibleObject", override_offset, k, vmSymbols::override_name(), vmSymbols::bool_signature());
+  compute_offset(override_offset, k, vmSymbols::override_name(), vmSymbols::bool_signature());
 }
 
 jboolean java_lang_reflect_AccessibleObject::override(oop reflect) {
@@ -1413,22 +1418,22 @@
 
 void java_lang_reflect_Method::compute_offsets() {
   klassOop k = SystemDictionary::reflect_method_klass();
-  COMPUTE_OFFSET("java.lang.reflect.Method", clazz_offset,          k, vmSymbols::clazz_name(),          vmSymbols::class_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Method", name_offset,           k, vmSymbols::name_name(),           vmSymbols::string_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Method", returnType_offset,     k, vmSymbols::returnType_name(),     vmSymbols::class_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Method", parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Method", exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Method", slot_offset,           k, vmSymbols::slot_name(),           vmSymbols::int_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Method", modifiers_offset,      k, vmSymbols::modifiers_name(),      vmSymbols::int_signature());
+  compute_offset(clazz_offset,          k, vmSymbols::clazz_name(),          vmSymbols::class_signature());
+  compute_offset(name_offset,           k, vmSymbols::name_name(),           vmSymbols::string_signature());
+  compute_offset(returnType_offset,     k, vmSymbols::returnType_name(),     vmSymbols::class_signature());
+  compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature());
+  compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature());
+  compute_offset(slot_offset,           k, vmSymbols::slot_name(),           vmSymbols::int_signature());
+  compute_offset(modifiers_offset,      k, vmSymbols::modifiers_name(),      vmSymbols::int_signature());
   // The generic signature and annotations fields are only present in 1.5
   signature_offset = -1;
   annotations_offset = -1;
   parameter_annotations_offset = -1;
   annotation_default_offset = -1;
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Method", signature_offset,             k, vmSymbols::signature_name(),             vmSymbols::string_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Method", annotations_offset,           k, vmSymbols::annotations_name(),           vmSymbols::byte_array_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Method", parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Method", annotation_default_offset,    k, vmSymbols::annotation_default_name(),    vmSymbols::byte_array_signature());
+  compute_optional_offset(signature_offset,             k, vmSymbols::signature_name(),             vmSymbols::string_signature());
+  compute_optional_offset(annotations_offset,           k, vmSymbols::annotations_name(),           vmSymbols::byte_array_signature());
+  compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature());
+  compute_optional_offset(annotation_default_offset,    k, vmSymbols::annotation_default_name(),    vmSymbols::byte_array_signature());
 }
 
 Handle java_lang_reflect_Method::create(TRAPS) {
@@ -1576,18 +1581,18 @@
 
 void java_lang_reflect_Constructor::compute_offsets() {
   klassOop k = SystemDictionary::reflect_constructor_klass();
-  COMPUTE_OFFSET("java.lang.reflect.Constructor", clazz_offset,          k, vmSymbols::clazz_name(),          vmSymbols::class_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Constructor", parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Constructor", exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Constructor", slot_offset,           k, vmSymbols::slot_name(),           vmSymbols::int_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Constructor", modifiers_offset,      k, vmSymbols::modifiers_name(),      vmSymbols::int_signature());
+  compute_offset(clazz_offset,          k, vmSymbols::clazz_name(),          vmSymbols::class_signature());
+  compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature());
+  compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature());
+  compute_offset(slot_offset,           k, vmSymbols::slot_name(),           vmSymbols::int_signature());
+  compute_offset(modifiers_offset,      k, vmSymbols::modifiers_name(),      vmSymbols::int_signature());
   // The generic signature and annotations fields are only present in 1.5
   signature_offset = -1;
   annotations_offset = -1;
   parameter_annotations_offset = -1;
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Constructor", signature_offset,             k, vmSymbols::signature_name(),             vmSymbols::string_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Constructor", annotations_offset,           k, vmSymbols::annotations_name(),           vmSymbols::byte_array_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Constructor", parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature());
+  compute_optional_offset(signature_offset,             k, vmSymbols::signature_name(),             vmSymbols::string_signature());
+  compute_optional_offset(annotations_offset,           k, vmSymbols::annotations_name(),           vmSymbols::byte_array_signature());
+  compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature());
 }
 
 Handle java_lang_reflect_Constructor::create(TRAPS) {
@@ -1700,16 +1705,16 @@
 
 void java_lang_reflect_Field::compute_offsets() {
   klassOop k = SystemDictionary::reflect_field_klass();
-  COMPUTE_OFFSET("java.lang.reflect.Field", clazz_offset,     k, vmSymbols::clazz_name(),     vmSymbols::class_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Field", name_offset,      k, vmSymbols::name_name(),      vmSymbols::string_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Field", type_offset,      k, vmSymbols::type_name(),      vmSymbols::class_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Field", slot_offset,      k, vmSymbols::slot_name(),      vmSymbols::int_signature());
-  COMPUTE_OFFSET("java.lang.reflect.Field", modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature());
+  compute_offset(clazz_offset,     k, vmSymbols::clazz_name(),     vmSymbols::class_signature());
+  compute_offset(name_offset,      k, vmSymbols::name_name(),      vmSymbols::string_signature());
+  compute_offset(type_offset,      k, vmSymbols::type_name(),      vmSymbols::class_signature());
+  compute_offset(slot_offset,      k, vmSymbols::slot_name(),      vmSymbols::int_signature());
+  compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature());
   // The generic signature and annotations fields are only present in 1.5
   signature_offset = -1;
   annotations_offset = -1;
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Field", signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature());
-  COMPUTE_OPTIONAL_OFFSET("java.lang.reflect.Field", annotations_offset,  k, vmSymbols::annotations_name(),  vmSymbols::byte_array_signature());
+  compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature());
+  compute_optional_offset(annotations_offset,  k, vmSymbols::annotations_name(),  vmSymbols::byte_array_signature());
 }
 
 Handle java_lang_reflect_Field::create(TRAPS) {
@@ -1809,7 +1814,7 @@
   klassOop k = SystemDictionary::reflect_constant_pool_klass();
   // This null test can be removed post beta
   if (k != NULL) {
-    COMPUTE_OFFSET("sun.reflect.ConstantPool", _cp_oop_offset, k, vmSymbols::constantPoolOop_name(), vmSymbols::object_signature());
+    compute_offset(_cp_oop_offset, k, vmSymbols::constantPoolOop_name(), vmSymbols::object_signature());
   }
 }
 
@@ -1839,51 +1844,46 @@
   klassOop k = SystemDictionary::reflect_unsafe_static_field_accessor_impl_klass();
   // This null test can be removed post beta
   if (k != NULL) {
-    COMPUTE_OFFSET("sun.reflect.UnsafeStaticFieldAccessorImpl", _base_offset, k,
+    compute_offset(_base_offset, k,
                    vmSymbols::base_name(), vmSymbols::object_signature());
   }
 }
 
-oop java_lang_boxing_object::initialize_and_allocate(klassOop k, TRAPS) {
- instanceKlassHandle h (THREAD, k);
- if (!h->is_initialized()) h->initialize(CHECK_0);
- return h->allocate_instance(THREAD);
+oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
+  klassOop k = SystemDictionary::box_klass(type);
+  if (k == NULL)  return NULL;
+  instanceKlassHandle h (THREAD, k);
+  if (!h->is_initialized())  h->initialize(CHECK_0);
+  return h->allocate_instance(THREAD);
 }
 
 
 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) {
-  oop box;
+  oop box = initialize_and_allocate(type, CHECK_0);
+  if (box == NULL)  return NULL;
   switch (type) {
     case T_BOOLEAN:
-      box = initialize_and_allocate(SystemDictionary::boolean_klass(), CHECK_0);
       box->bool_field_put(value_offset, value->z);
       break;
     case T_CHAR:
-      box = initialize_and_allocate(SystemDictionary::char_klass(), CHECK_0);
       box->char_field_put(value_offset, value->c);
       break;
     case T_FLOAT:
-      box = initialize_and_allocate(SystemDictionary::float_klass(), CHECK_0);
       box->float_field_put(value_offset, value->f);
       break;
     case T_DOUBLE:
-      box = initialize_and_allocate(SystemDictionary::double_klass(), CHECK_0);
       box->double_field_put(value_offset, value->d);
       break;
     case T_BYTE:
-      box = initialize_and_allocate(SystemDictionary::byte_klass(), CHECK_0);
       box->byte_field_put(value_offset, value->b);
       break;
     case T_SHORT:
-      box = initialize_and_allocate(SystemDictionary::short_klass(), CHECK_0);
       box->short_field_put(value_offset, value->s);
       break;
     case T_INT:
-      box = initialize_and_allocate(SystemDictionary::int_klass(), CHECK_0);
       box->int_field_put(value_offset, value->i);
       break;
     case T_LONG:
-      box = initialize_and_allocate(SystemDictionary::long_klass(), CHECK_0);
       box->long_field_put(value_offset, value->j);
       break;
     default:
@@ -1893,79 +1893,80 @@
 }
 
 
+BasicType java_lang_boxing_object::basic_type(oop box) {
+  if (box == NULL)  return T_ILLEGAL;
+  BasicType type = SystemDictionary::box_klass_type(box->klass());
+  if (type == T_OBJECT)         // 'unknown' value returned by SD::bkt
+    return T_ILLEGAL;
+  return type;
+}
+
+
 BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) {
-  klassOop k = box->klass();
-  if (k == SystemDictionary::boolean_klass()) {
+  BasicType type = SystemDictionary::box_klass_type(box->klass());
+  switch (type) {
+  case T_BOOLEAN:
     value->z = box->bool_field(value_offset);
-    return T_BOOLEAN;
-  }
-  if (k == SystemDictionary::char_klass()) {
+    break;
+  case T_CHAR:
     value->c = box->char_field(value_offset);
-    return T_CHAR;
-  }
-  if (k == SystemDictionary::float_klass()) {
+    break;
+  case T_FLOAT:
     value->f = box->float_field(value_offset);
-    return T_FLOAT;
-  }
-  if (k == SystemDictionary::double_klass()) {
+    break;
+  case T_DOUBLE:
     value->d = box->double_field(value_offset);
-    return T_DOUBLE;
-  }
-  if (k == SystemDictionary::byte_klass()) {
+    break;
+  case T_BYTE:
     value->b = box->byte_field(value_offset);
-    return T_BYTE;
-  }
-  if (k == SystemDictionary::short_klass()) {
+    break;
+  case T_SHORT:
     value->s = box->short_field(value_offset);
-    return T_SHORT;
-  }
-  if (k == SystemDictionary::int_klass()) {
+    break;
+  case T_INT:
     value->i = box->int_field(value_offset);
-    return T_INT;
-  }
-  if (k == SystemDictionary::long_klass()) {
+    break;
+  case T_LONG:
     value->j = box->long_field(value_offset);
-    return T_LONG;
-  }
-  return T_ILLEGAL;
+    break;
+  default:
+    return T_ILLEGAL;
+  } // end switch
+  return type;
 }
 
 
 BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) {
-  klassOop k = box->klass();
-  if (k == SystemDictionary::boolean_klass()) {
+  BasicType type = SystemDictionary::box_klass_type(box->klass());
+  switch (type) {
+  case T_BOOLEAN:
     box->bool_field_put(value_offset, value->z);
-    return T_BOOLEAN;
-  }
-  if (k == SystemDictionary::char_klass()) {
+    break;
+  case T_CHAR:
     box->char_field_put(value_offset, value->c);
-    return T_CHAR;
-  }
-  if (k == SystemDictionary::float_klass()) {
+    break;
+  case T_FLOAT:
     box->float_field_put(value_offset, value->f);
-    return T_FLOAT;
-  }
-  if (k == SystemDictionary::double_klass()) {
+    break;
+  case T_DOUBLE:
     box->double_field_put(value_offset, value->d);
-    return T_DOUBLE;
-  }
-  if (k == SystemDictionary::byte_klass()) {
+    break;
+  case T_BYTE:
     box->byte_field_put(value_offset, value->b);
-    return T_BYTE;
-  }
-  if (k == SystemDictionary::short_klass()) {
+    break;
+  case T_SHORT:
     box->short_field_put(value_offset, value->s);
-    return T_SHORT;
-  }
-  if (k == SystemDictionary::int_klass()) {
+    break;
+  case T_INT:
     box->int_field_put(value_offset, value->i);
-    return T_INT;
-  }
-  if (k == SystemDictionary::long_klass()) {
+    break;
+  case T_LONG:
     box->long_field_put(value_offset, value->j);
-    return T_LONG;
-  }
-  return T_ILLEGAL;
+    break;
+  default:
+    return T_ILLEGAL;
+  } // end switch
+  return type;
 }
 
 
@@ -2242,7 +2243,8 @@
 
 void java_nio_Buffer::compute_offsets() {
   klassOop k = SystemDictionary::java_nio_Buffer_klass();
-  COMPUTE_OFFSET("java.nio.Buffer", _limit_offset, k, vmSymbols::limit_name(), vmSymbols::int_signature());
+  assert(k != NULL, "must be loaded in 1.4+");
+  compute_offset(_limit_offset, k, vmSymbols::limit_name(), vmSymbols::int_signature());
 }
 
 // Support for intrinsification of sun.misc.AtomicLongCSImpl.attemptUpdate
@@ -2256,7 +2258,7 @@
   klassOop k = SystemDictionary::sun_misc_AtomicLongCSImpl_klass();
   // If this class is not present, its value field offset won't be referenced.
   if (k != NULL) {
-    COMPUTE_OFFSET("sun.misc.AtomicLongCSImpl", _value_offset, k, vmSymbols::value_name(), vmSymbols::long_signature());
+    compute_offset(_value_offset, k, vmSymbols::value_name(), vmSymbols::long_signature());
   }
 }
 
@@ -2266,7 +2268,7 @@
   assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later");
   SystemDictionary::load_abstract_ownable_synchronizer_klass(CHECK);
   klassOop k = SystemDictionary::abstract_ownable_synchronizer_klass();
-  COMPUTE_OFFSET("java.util.concurrent.locks.AbstractOwnableSynchronizer", _owner_offset, k,
+  compute_offset(_owner_offset, k,
                  vmSymbols::exclusive_owner_thread_name(), vmSymbols::thread_signature());
 }
 
@@ -2429,6 +2431,36 @@
 }
 
 
+bool JavaClasses::check_constant(const char *klass_name, int hardcoded_constant, const char *field_name, const char* field_sig) {
+  EXCEPTION_MARK;
+  fieldDescriptor fd;
+  symbolHandle klass_sym = oopFactory::new_symbol_handle(klass_name, CATCH);
+  klassOop k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
+  instanceKlassHandle h_klass (THREAD, k);
+  symbolHandle f_name = oopFactory::new_symbol_handle(field_name, CATCH);
+  symbolHandle f_sig  = oopFactory::new_symbol_handle(field_sig, CATCH);
+  if (!h_klass->find_local_field(f_name(), f_sig(), &fd)) {
+    tty->print_cr("Static field %s.%s not found", klass_name, field_name);
+    return false;
+  }
+  if (!fd.is_static() || !fd.has_initial_value()) {
+    tty->print_cr("Static field %s.%s appears to be non-constant", klass_name, field_name);
+    return false;
+  }
+  if (!fd.initial_value_tag().is_int()) {
+    tty->print_cr("Static field %s.%s is not an int", klass_name, field_name);
+    return false;
+  }
+  jint field_value = fd.int_initial_value();
+  if (field_value == hardcoded_constant) {
+    return true;
+  } else {
+    tty->print_cr("Constant value of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_constant, field_value);
+    return false;
+  }
+}
+
+
 // Check the hard-coded field offsets of all the classes in this file
 
 void JavaClasses::check_offsets() {
@@ -2440,6 +2472,9 @@
 #define CHECK_STATIC_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
   valid &= check_static_offset(klass_name, cpp_klass_name :: static_ ## field_name ## _offset, #field_name, field_sig)
 
+#define CHECK_CONSTANT(klass_name, cpp_klass_name, field_name, field_sig) \
+  valid &= check_constant(klass_name, cpp_klass_name :: field_name, #field_name, field_sig)
+
   // java.lang.String
 
   CHECK_OFFSET("java/lang/String", java_lang_String, value, "[C");