src/hotspot/share/classfile/javaClasses.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54847 59ea39bb2809
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    62 #include "runtime/jniHandles.inline.hpp"
    62 #include "runtime/jniHandles.inline.hpp"
    63 #include "runtime/safepoint.hpp"
    63 #include "runtime/safepoint.hpp"
    64 #include "runtime/safepointVerifiers.hpp"
    64 #include "runtime/safepointVerifiers.hpp"
    65 #include "runtime/thread.inline.hpp"
    65 #include "runtime/thread.inline.hpp"
    66 #include "runtime/vframe.inline.hpp"
    66 #include "runtime/vframe.inline.hpp"
       
    67 #include "runtime/vm_version.hpp"
    67 #include "utilities/align.hpp"
    68 #include "utilities/align.hpp"
    68 #include "utilities/preserveException.hpp"
    69 #include "utilities/preserveException.hpp"
    69 #include "utilities/utf8.hpp"
    70 #include "utilities/utf8.hpp"
    70 #if INCLUDE_JVMCI
    71 #if INCLUDE_JVMCI
    71 #include "jvmci/jvmciJavaClasses.hpp"
    72 #include "jvmci/jvmciJavaClasses.hpp"
   196 }
   197 }
   197 
   198 
   198 #if INCLUDE_CDS
   199 #if INCLUDE_CDS
   199 void java_lang_String::serialize_offsets(SerializeClosure* f) {
   200 void java_lang_String::serialize_offsets(SerializeClosure* f) {
   200   STRING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
   201   STRING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
   201   f->do_u4((u4*)&initialized);
   202   f->do_bool(&initialized);
   202 }
   203 }
   203 #endif
   204 #endif
   204 
   205 
   205 class CompactStringsFixup : public FieldClosure {
   206 class CompactStringsFixup : public FieldClosure {
   206 private:
   207 private:
   374   typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *);
   375   typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *);
   375   static to_java_string_fn_t _to_java_string_fn = NULL;
   376   static to_java_string_fn_t _to_java_string_fn = NULL;
   376 
   377 
   377   if (_to_java_string_fn == NULL) {
   378   if (_to_java_string_fn == NULL) {
   378     void *lib_handle = os::native_java_library();
   379     void *lib_handle = os::native_java_library();
   379     _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "NewStringPlatform"));
   380     _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "JNU_NewStringPlatform"));
   380     if (_to_java_string_fn == NULL) {
   381     if (_to_java_string_fn == NULL) {
   381       fatal("NewStringPlatform missing");
   382       fatal("NewStringPlatform missing");
   382     }
   383     }
   383   }
   384   }
   384 
   385 
   385   jstring js = NULL;
   386   jstring js = NULL;
   386   { JavaThread* thread = (JavaThread*)THREAD;
   387   {
   387     assert(thread->is_Java_thread(), "must be java thread");
   388     assert(THREAD->is_Java_thread(), "must be java thread");
       
   389     JavaThread* thread = (JavaThread*)THREAD;
   388     HandleMark hm(thread);
   390     HandleMark hm(thread);
   389     ThreadToNativeFromVM ttn(thread);
   391     ThreadToNativeFromVM ttn(thread);
   390     js = (_to_java_string_fn)(thread->jni_environment(), str);
   392     js = (_to_java_string_fn)(thread->jni_environment(), str);
   391   }
   393   }
   392   return Handle(THREAD, JNIHandles::resolve(js));
   394 
       
   395   Handle native_platform_string(THREAD, JNIHandles::resolve(js));
       
   396   JNIHandles::destroy_local(js);  // destroy local JNIHandle.
       
   397   return native_platform_string;
   393 }
   398 }
   394 
   399 
   395 // Converts a Java String to a native C string that can be used for
   400 // Converts a Java String to a native C string that can be used for
   396 // native OS calls.
   401 // native OS calls.
   397 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
   402 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) {
   875       set_module(mirror(), javabase_handle());
   880       set_module(mirror(), javabase_handle());
   876     }
   881     }
   877   } else {
   882   } else {
   878     assert(Universe::is_module_initialized() ||
   883     assert(Universe::is_module_initialized() ||
   879            (ModuleEntryTable::javabase_defined() &&
   884            (ModuleEntryTable::javabase_defined() &&
   880             (oopDesc::equals(module(), ModuleEntryTable::javabase_moduleEntry()->module()))),
   885             (module() == ModuleEntryTable::javabase_moduleEntry()->module())),
   881            "Incorrect java.lang.Module specification while creating mirror");
   886            "Incorrect java.lang.Module specification while creating mirror");
   882     set_module(mirror(), module());
   887     set_module(mirror(), module());
   883   }
   888   }
   884 }
   889 }
   885 
   890 
   952         return;
   957         return;
   953       }
   958       }
   954     }
   959     }
   955 
   960 
   956     // set the classLoader field in the java_lang_Class instance
   961     // set the classLoader field in the java_lang_Class instance
   957     assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same");
   962     assert(class_loader() == k->class_loader(), "should be same");
   958     set_class_loader(mirror(), class_loader());
   963     set_class_loader(mirror(), class_loader());
   959 
   964 
   960     // Setup indirection from klass->mirror
   965     // Setup indirection from klass->mirror
   961     // after any exceptions can happen during allocations.
   966     // after any exceptions can happen during allocations.
   962     k->set_java_mirror(mirror);
   967     k->set_java_mirror(mirror);
  1507   BasicType type = T_VOID;
  1512   BasicType type = T_VOID;
  1508   if (ak != NULL) {
  1513   if (ak != NULL) {
  1509     // Note: create_basic_type_mirror above initializes ak to a non-null value.
  1514     // Note: create_basic_type_mirror above initializes ak to a non-null value.
  1510     type = ArrayKlass::cast(ak)->element_type();
  1515     type = ArrayKlass::cast(ak)->element_type();
  1511   } else {
  1516   } else {
  1512     assert(oopDesc::equals(java_class, Universe::void_mirror()), "only valid non-array primitive");
  1517     assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
  1513   }
  1518   }
  1514   assert(oopDesc::equals(Universe::java_mirror(type), java_class), "must be consistent");
  1519   assert(Universe::java_mirror(type) == java_class, "must be consistent");
  1515   return type;
  1520   return type;
  1516 }
  1521 }
  1517 
  1522 
  1518 BasicType java_lang_Class::as_BasicType(oop java_class, Klass** reference_klass) {
  1523 BasicType java_lang_Class::as_BasicType(oop java_class, Klass** reference_klass) {
  1519   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
  1524   assert(java_lang_Class::is_instance(java_class), "must be a Class object");
  1538 
  1543 
  1539 bool java_lang_Class::offsets_computed = false;
  1544 bool java_lang_Class::offsets_computed = false;
  1540 int  java_lang_Class::classRedefinedCount_offset = -1;
  1545 int  java_lang_Class::classRedefinedCount_offset = -1;
  1541 
  1546 
  1542 #define CLASS_FIELDS_DO(macro) \
  1547 #define CLASS_FIELDS_DO(macro) \
  1543   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false) ; \
  1548   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
  1544   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
  1549   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
  1545   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
  1550   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
  1546   macro(_module_offset,             k, "module",              module_signature,      false); \
  1551   macro(_module_offset,             k, "module",              module_signature,      false); \
  1547   macro(_name_offset,               k, "name",                string_signature,      false); \
  1552   macro(_name_offset,               k, "name",                string_signature,      false); \
  1548 
  1553 
  1564   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  1569   CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  1565 }
  1570 }
  1566 
  1571 
  1567 #if INCLUDE_CDS
  1572 #if INCLUDE_CDS
  1568 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
  1573 void java_lang_Class::serialize_offsets(SerializeClosure* f) {
  1569   f->do_u4((u4*)&offsets_computed);
  1574   f->do_bool(&offsets_computed);
  1570   f->do_u4((u4*)&_init_lock_offset);
  1575   f->do_u4((u4*)&_init_lock_offset);
  1571 
  1576 
  1572   CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
  1577   CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
  1573 
  1578 
  1574   CLASS_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET);
  1579   CLASS_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET);
  1931 static inline bool version_matches(Method* method, int version) {
  1936 static inline bool version_matches(Method* method, int version) {
  1932   assert(version < MAX_VERSION, "version is too big");
  1937   assert(version < MAX_VERSION, "version is too big");
  1933   return method != NULL && (method->constants()->version() == version);
  1938   return method != NULL && (method->constants()->version() == version);
  1934 }
  1939 }
  1935 
  1940 
  1936 
       
  1937 // This class provides a simple wrapper over the internal structure of
  1941 // This class provides a simple wrapper over the internal structure of
  1938 // exception backtrace to insulate users of the backtrace from needing
  1942 // exception backtrace to insulate users of the backtrace from needing
  1939 // to know what it looks like.
  1943 // to know what it looks like.
  1940 class BacktraceBuilder: public StackObj {
  1944 class BacktraceBuilder: public StackObj {
  1941  friend class BacktraceIterator;
  1945  friend class BacktraceIterator;
  1943   Handle          _backtrace;
  1947   Handle          _backtrace;
  1944   objArrayOop     _head;
  1948   objArrayOop     _head;
  1945   typeArrayOop    _methods;
  1949   typeArrayOop    _methods;
  1946   typeArrayOop    _bcis;
  1950   typeArrayOop    _bcis;
  1947   objArrayOop     _mirrors;
  1951   objArrayOop     _mirrors;
  1948   typeArrayOop    _names; // needed to insulate method name against redefinition
  1952   typeArrayOop    _names; // Needed to insulate method name against redefinition.
       
  1953   // This is set to a java.lang.Boolean(true) if the top frame
       
  1954   // of the backtrace is omitted because it shall be hidden.
       
  1955   // Else it is null.
       
  1956   oop             _has_hidden_top_frame;
  1949   int             _index;
  1957   int             _index;
  1950   NoSafepointVerifier _nsv;
  1958   NoSafepointVerifier _nsv;
  1951 
  1959 
  1952   enum {
  1960   enum {
  1953     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
  1961     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
  1954     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
  1962     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
  1955     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
  1963     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
  1956     trace_names_offset   = java_lang_Throwable::trace_names_offset,
  1964     trace_names_offset   = java_lang_Throwable::trace_names_offset,
  1957     trace_next_offset    = java_lang_Throwable::trace_next_offset,
  1965     trace_next_offset    = java_lang_Throwable::trace_next_offset,
       
  1966     trace_hidden_offset  = java_lang_Throwable::trace_hidden_offset,
  1958     trace_size           = java_lang_Throwable::trace_size,
  1967     trace_size           = java_lang_Throwable::trace_size,
  1959     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
  1968     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
  1960   };
  1969   };
  1961 
  1970 
  1962   // get info out of chunks
  1971   // get info out of chunks
  1978   static typeArrayOop get_names(objArrayHandle chunk) {
  1987   static typeArrayOop get_names(objArrayHandle chunk) {
  1979     typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
  1988     typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
  1980     assert(names != NULL, "names array should be initialized in backtrace");
  1989     assert(names != NULL, "names array should be initialized in backtrace");
  1981     return names;
  1990     return names;
  1982   }
  1991   }
       
  1992   static oop get_has_hidden_top_frame(objArrayHandle chunk) {
       
  1993     oop hidden = chunk->obj_at(trace_hidden_offset);
       
  1994     return hidden;
       
  1995   }
  1983 
  1996 
  1984  public:
  1997  public:
  1985 
  1998 
  1986   // constructor for new backtrace
  1999   // constructor for new backtrace
  1987   BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL) {
  2000   BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL), _has_hidden_top_frame(NULL) {
  1988     expand(CHECK);
  2001     expand(CHECK);
  1989     _backtrace = Handle(THREAD, _head);
  2002     _backtrace = Handle(THREAD, _head);
  1990     _index = 0;
  2003     _index = 0;
  1991   }
  2004   }
  1992 
  2005 
  1993   BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
  2006   BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
  1994     _methods = get_methods(backtrace);
  2007     _methods = get_methods(backtrace);
  1995     _bcis = get_bcis(backtrace);
  2008     _bcis = get_bcis(backtrace);
  1996     _mirrors = get_mirrors(backtrace);
  2009     _mirrors = get_mirrors(backtrace);
  1997     _names = get_names(backtrace);
  2010     _names = get_names(backtrace);
       
  2011     _has_hidden_top_frame = get_has_hidden_top_frame(backtrace);
  1998     assert(_methods->length() == _bcis->length() &&
  2012     assert(_methods->length() == _bcis->length() &&
  1999            _methods->length() == _mirrors->length() &&
  2013            _methods->length() == _mirrors->length() &&
  2000            _mirrors->length() == _names->length(),
  2014            _mirrors->length() == _names->length(),
  2001            "method and source information arrays should match");
  2015            "method and source information arrays should match");
  2002 
  2016 
  2030     }
  2044     }
  2031     new_head->obj_at_put(trace_methods_offset, new_methods());
  2045     new_head->obj_at_put(trace_methods_offset, new_methods());
  2032     new_head->obj_at_put(trace_bcis_offset, new_bcis());
  2046     new_head->obj_at_put(trace_bcis_offset, new_bcis());
  2033     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
  2047     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
  2034     new_head->obj_at_put(trace_names_offset, new_names());
  2048     new_head->obj_at_put(trace_names_offset, new_names());
       
  2049     new_head->obj_at_put(trace_hidden_offset, NULL);
  2035 
  2050 
  2036     _head    = new_head();
  2051     _head    = new_head();
  2037     _methods = new_methods();
  2052     _methods = new_methods();
  2038     _bcis = new_bcis();
  2053     _bcis = new_bcis();
  2039     _mirrors = new_mirrors();
  2054     _mirrors = new_mirrors();
  2068     // We need to save the mirrors in the backtrace to keep the class
  2083     // We need to save the mirrors in the backtrace to keep the class
  2069     // from being unloaded while we still have this stack trace.
  2084     // from being unloaded while we still have this stack trace.
  2070     assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror");
  2085     assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror");
  2071     _mirrors->obj_at_put(_index, method->method_holder()->java_mirror());
  2086     _mirrors->obj_at_put(_index, method->method_holder()->java_mirror());
  2072     _index++;
  2087     _index++;
       
  2088   }
       
  2089 
       
  2090   void set_has_hidden_top_frame(TRAPS) {
       
  2091     if (_has_hidden_top_frame == NULL) {
       
  2092       jvalue prim;
       
  2093       prim.z = 1;
       
  2094       PauseNoSafepointVerifier pnsv(&_nsv);
       
  2095       _has_hidden_top_frame = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK);
       
  2096       _head->obj_at_put(trace_hidden_offset, _has_hidden_top_frame);
       
  2097     }
  2073   }
  2098   }
  2074 
  2099 
  2075 };
  2100 };
  2076 
  2101 
  2077 struct BacktraceElement : public StackObj {
  2102 struct BacktraceElement : public StackObj {
  2399         // there are none or we've seen them all - either way stop checking
  2424         // there are none or we've seen them all - either way stop checking
  2400         skip_throwableInit_check = true;
  2425         skip_throwableInit_check = true;
  2401       }
  2426       }
  2402     }
  2427     }
  2403     if (method->is_hidden()) {
  2428     if (method->is_hidden()) {
  2404       if (skip_hidden)  continue;
  2429       if (skip_hidden) {
       
  2430         if (total_count == 0) {
       
  2431           // The top frame will be hidden from the stack trace.
       
  2432           bt.set_has_hidden_top_frame(CHECK);
       
  2433         }
       
  2434         continue;
       
  2435       }
  2405     }
  2436     }
  2406     bt.push(method, bci, CHECK);
  2437     bt.push(method, bci, CHECK);
  2407     total_count++;
  2438     total_count++;
  2408   }
  2439   }
  2409 
  2440 
  2514                                          method,
  2545                                          method,
  2515                                          bte._version,
  2546                                          bte._version,
  2516                                          bte._bci,
  2547                                          bte._bci,
  2517                                          bte._name, CHECK);
  2548                                          bte._name, CHECK);
  2518   }
  2549   }
       
  2550 }
       
  2551 
       
  2552 bool java_lang_Throwable::get_top_method_and_bci(oop throwable, Method** method, int* bci) {
       
  2553   Thread* THREAD = Thread::current();
       
  2554   objArrayHandle result(THREAD, objArrayOop(backtrace(throwable)));
       
  2555   BacktraceIterator iter(result, THREAD);
       
  2556   // No backtrace available.
       
  2557   if (!iter.repeat()) return false;
       
  2558 
       
  2559   // If the exception happened in a frame that has been hidden, i.e.,
       
  2560   // omitted from the back trace, we can not compute the message.
       
  2561   oop hidden = ((objArrayOop)backtrace(throwable))->obj_at(trace_hidden_offset);
       
  2562   if (hidden != NULL) {
       
  2563     return false;
       
  2564   }
       
  2565 
       
  2566   // Get first backtrace element.
       
  2567   BacktraceElement bte = iter.next(THREAD);
       
  2568 
       
  2569   InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
       
  2570   assert(holder != NULL, "first element should be non-null");
       
  2571   Method* m = holder->method_with_orig_idnum(bte._method_id, bte._version);
       
  2572 
       
  2573   // Original version is no longer available.
       
  2574   if (m == NULL || !version_matches(m, bte._version)) {
       
  2575     return false;
       
  2576   }
       
  2577 
       
  2578   *method = m;
       
  2579   *bci = bte._bci;
       
  2580   return true;
  2519 }
  2581 }
  2520 
  2582 
  2521 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
  2583 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
  2522   // Allocate java.lang.StackTraceElement instance
  2584   // Allocate java.lang.StackTraceElement instance
  2523   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
  2585   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
  2591       // Class was redefined. Dump the cache if it was set.
  2653       // Class was redefined. Dump the cache if it was set.
  2592       if (source_file != NULL) {
  2654       if (source_file != NULL) {
  2593         source_file = NULL;
  2655         source_file = NULL;
  2594         java_lang_Class::set_source_file(java_class(), source_file);
  2656         java_lang_Class::set_source_file(java_class(), source_file);
  2595       }
  2657       }
  2596       if (ShowHiddenFrames) {
       
  2597         source = vmSymbols::unknown_class_name();
       
  2598         source_file = StringTable::intern(source, CHECK);
       
  2599       }
       
  2600     }
  2658     }
  2601     java_lang_StackTraceElement::set_fileName(element(), source_file);
  2659     java_lang_StackTraceElement::set_fileName(element(), source_file);
  2602 
  2660 
  2603     int line_number = Backtrace::get_line_number(method, bci);
  2661     int line_number = Backtrace::get_line_number(method, bci);
  2604     java_lang_StackTraceElement::set_lineNumber(element(), line_number);
  2662     java_lang_StackTraceElement::set_lineNumber(element(), line_number);
  2632     // Use a specific ik version as a holder since the mirror might
  2690     // Use a specific ik version as a holder since the mirror might
  2633     // refer to a version that is now obsolete and no longer accessible
  2691     // refer to a version that is now obsolete and no longer accessible
  2634     // via the previous versions list.
  2692     // via the previous versions list.
  2635     holder = holder->get_klass_version(version);
  2693     holder = holder->get_klass_version(version);
  2636     assert(holder != NULL, "sanity check");
  2694     assert(holder != NULL, "sanity check");
  2637     Symbol* source = holder->source_file_name();
  2695     filename = holder->source_file_name();
  2638     if (ShowHiddenFrames && source == NULL) {
       
  2639       source = vmSymbols::unknown_class_name();
       
  2640     }
       
  2641     filename = source;
       
  2642     line_number = Backtrace::get_line_number(method, bci);
  2696     line_number = Backtrace::get_line_number(method, bci);
  2643   }
  2697   }
  2644 }
  2698 }
  2645 #endif // INCLUDE_JVMCI
  2699 #endif // INCLUDE_JVMCI
  2646 
  2700 
  2675   Klass* clazz = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
  2729   Klass* clazz = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
  2676   InstanceKlass* holder = InstanceKlass::cast(clazz);
  2730   InstanceKlass* holder = InstanceKlass::cast(clazz);
  2677   Method* method = java_lang_StackFrameInfo::get_method(stackFrame, holder, CHECK);
  2731   Method* method = java_lang_StackFrameInfo::get_method(stackFrame, holder, CHECK);
  2678 
  2732 
  2679   short version = stackFrame->short_field(_version_offset);
  2733   short version = stackFrame->short_field(_version_offset);
  2680   short bci = stackFrame->short_field(_bci_offset);
  2734   int bci = stackFrame->int_field(_bci_offset);
  2681   Symbol* name = method->name();
  2735   Symbol* name = method->name();
  2682   java_lang_StackTraceElement::fill_in(stack_trace_element, holder, method, version, bci, name, CHECK);
  2736   java_lang_StackTraceElement::fill_in(stack_trace_element, holder, method, version, bci, name, CHECK);
  2683 }
  2737 }
  2684 
  2738 
  2685 #define STACKFRAMEINFO_FIELDS_DO(macro) \
  2739 #define STACKFRAMEINFO_FIELDS_DO(macro) \
  2686   macro(_memberName_offset,     k, "memberName",  object_signature, false); \
  2740   macro(_memberName_offset,     k, "memberName",  object_signature, false); \
  2687   macro(_bci_offset,            k, "bci",         short_signature,  false)
  2741   macro(_bci_offset,            k, "bci",         int_signature,    false)
  2688 
  2742 
  2689 void java_lang_StackFrameInfo::compute_offsets() {
  2743 void java_lang_StackFrameInfo::compute_offsets() {
  2690   InstanceKlass* k = SystemDictionary::StackFrameInfo_klass();
  2744   InstanceKlass* k = SystemDictionary::StackFrameInfo_klass();
  2691   STACKFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
  2745   STACKFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
  2692   STACKFRAMEINFO_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  2746   STACKFRAMEINFO_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  3717   }
  3771   }
  3718   return name;
  3772   return name;
  3719 }
  3773 }
  3720 
  3774 
  3721 bool java_lang_invoke_MethodType::equals(oop mt1, oop mt2) {
  3775 bool java_lang_invoke_MethodType::equals(oop mt1, oop mt2) {
  3722   if (oopDesc::equals(mt1, mt2))
  3776   if (mt1 == mt2)
  3723     return true;
  3777     return true;
  3724   if (!oopDesc::equals(rtype(mt1), rtype(mt2)))
  3778   if (rtype(mt1) != rtype(mt2))
  3725     return false;
  3779     return false;
  3726   if (ptype_count(mt1) != ptype_count(mt2))
  3780   if (ptype_count(mt1) != ptype_count(mt2))
  3727     return false;
  3781     return false;
  3728   for (int i = ptype_count(mt1) - 1; i >= 0; i--) {
  3782   for (int i = ptype_count(mt1) - 1; i >= 0; i--) {
  3729     if (!oopDesc::equals(ptype(mt1, i), ptype(mt2, i)))
  3783     if (ptype(mt1, i) != ptype(mt2, i))
  3730       return false;
  3784       return false;
  3731   }
  3785   }
  3732   return true;
  3786   return true;
  3733 }
  3787 }
  3734 
  3788 
  3938   oop acl = loader;
  3992   oop acl = loader;
  3939   debug_only(jint loop_count = 0);
  3993   debug_only(jint loop_count = 0);
  3940   // This loop taken verbatim from ClassLoader.java:
  3994   // This loop taken verbatim from ClassLoader.java:
  3941   do {
  3995   do {
  3942     acl = parent(acl);
  3996     acl = parent(acl);
  3943     if (oopDesc::equals(cl, acl)) {
  3997     if (cl == acl) {
  3944       return true;
  3998       return true;
  3945     }
  3999     }
  3946     assert(++loop_count > 0, "loop_count overflow");
  4000     assert(++loop_count > 0, "loop_count overflow");
  3947   } while (acl != NULL);
  4001   } while (acl != NULL);
  3948   return false;
  4002   return false;
  3968   // Fix for 4474172; see evaluation for more details
  4022   // Fix for 4474172; see evaluation for more details
  3969   loader = non_reflection_class_loader(loader);
  4023   loader = non_reflection_class_loader(loader);
  3970 
  4024 
  3971   oop cl = SystemDictionary::java_system_loader();
  4025   oop cl = SystemDictionary::java_system_loader();
  3972   while(cl != NULL) {
  4026   while(cl != NULL) {
  3973     if (oopDesc::equals(cl, loader)) return true;
  4027     if (cl == loader) return true;
  3974     cl = parent(cl);
  4028     cl = parent(cl);
  3975   }
  4029   }
  3976   return false;
  4030   return false;
  3977 }
  4031 }
  3978 
  4032 
  4032 private:
  4086 private:
  4033   int _address_size;
  4087   int _address_size;
  4034   int _page_size;
  4088   int _page_size;
  4035   bool _big_endian;
  4089   bool _big_endian;
  4036   bool _use_unaligned_access;
  4090   bool _use_unaligned_access;
       
  4091   int _data_cache_line_flush_size;
  4037 public:
  4092 public:
  4038   UnsafeConstantsFixup() {
  4093   UnsafeConstantsFixup() {
  4039     // round up values for all static final fields
  4094     // round up values for all static final fields
  4040     _address_size = sizeof(void*);
  4095     _address_size = sizeof(void*);
  4041     _page_size = os::vm_page_size();
  4096     _page_size = os::vm_page_size();
  4042     _big_endian = LITTLE_ENDIAN_ONLY(false) BIG_ENDIAN_ONLY(true);
  4097     _big_endian = LITTLE_ENDIAN_ONLY(false) BIG_ENDIAN_ONLY(true);
  4043     _use_unaligned_access = UseUnalignedAccesses;
  4098     _use_unaligned_access = UseUnalignedAccesses;
       
  4099     _data_cache_line_flush_size = (int)VM_Version::data_cache_line_flush_size();
  4044   }
  4100   }
  4045 
  4101 
  4046   void do_field(fieldDescriptor* fd) {
  4102   void do_field(fieldDescriptor* fd) {
  4047     oop mirror = fd->field_holder()->java_mirror();
  4103     oop mirror = fd->field_holder()->java_mirror();
  4048     assert(mirror != NULL, "UnsafeConstants must have mirror already");
  4104     assert(mirror != NULL, "UnsafeConstants must have mirror already");
  4055       mirror->int_field_put(fd->offset(), _page_size);
  4111       mirror->int_field_put(fd->offset(), _page_size);
  4056     } else if (fd->name() == vmSymbols::big_endian_name()) {
  4112     } else if (fd->name() == vmSymbols::big_endian_name()) {
  4057       mirror->bool_field_put(fd->offset(), _big_endian);
  4113       mirror->bool_field_put(fd->offset(), _big_endian);
  4058     } else if (fd->name() == vmSymbols::use_unaligned_access_name()) {
  4114     } else if (fd->name() == vmSymbols::use_unaligned_access_name()) {
  4059       mirror->bool_field_put(fd->offset(), _use_unaligned_access);
  4115       mirror->bool_field_put(fd->offset(), _use_unaligned_access);
       
  4116     } else if (fd->name() == vmSymbols::data_cache_line_flush_size_name()) {
       
  4117       mirror->int_field_put(fd->offset(), _data_cache_line_flush_size);
  4060     } else {
  4118     } else {
  4061       assert(false, "unexpected UnsafeConstants field");
  4119       assert(false, "unexpected UnsafeConstants field");
  4062     }
  4120     }
  4063   }
  4121   }
  4064 };
  4122 };
  4153 int java_lang_AssertionStatusDirectives::deflt_offset;
  4211 int java_lang_AssertionStatusDirectives::deflt_offset;
  4154 int java_nio_Buffer::_limit_offset;
  4212 int java_nio_Buffer::_limit_offset;
  4155 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset;
  4213 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset;
  4156 int reflect_ConstantPool::_oop_offset;
  4214 int reflect_ConstantPool::_oop_offset;
  4157 int reflect_UnsafeStaticFieldAccessorImpl::_base_offset;
  4215 int reflect_UnsafeStaticFieldAccessorImpl::_base_offset;
       
  4216 int java_lang_Integer_IntegerCache::_static_cache_offset;
       
  4217 int java_lang_Long_LongCache::_static_cache_offset;
       
  4218 int java_lang_Character_CharacterCache::_static_cache_offset;
       
  4219 int java_lang_Short_ShortCache::_static_cache_offset;
       
  4220 int java_lang_Byte_ByteCache::_static_cache_offset;
       
  4221 int java_lang_Boolean::_static_TRUE_offset;
       
  4222 int java_lang_Boolean::_static_FALSE_offset;
       
  4223 
  4158 
  4224 
  4159 
  4225 
  4160 #define STACKTRACEELEMENT_FIELDS_DO(macro) \
  4226 #define STACKTRACEELEMENT_FIELDS_DO(macro) \
  4161   macro(declaringClassObject_offset,  k, "declaringClassObject", class_signature, false); \
  4227   macro(declaringClassObject_offset,  k, "declaringClassObject", class_signature, false); \
  4162   macro(classLoaderName_offset, k, "classLoaderName", string_signature, false); \
  4228   macro(classLoaderName_offset, k, "classLoaderName", string_signature, false); \
  4214 void java_lang_StackFrameInfo::set_version(oop element, short value) {
  4280 void java_lang_StackFrameInfo::set_version(oop element, short value) {
  4215   element->short_field_put(_version_offset, value);
  4281   element->short_field_put(_version_offset, value);
  4216 }
  4282 }
  4217 
  4283 
  4218 void java_lang_StackFrameInfo::set_bci(oop element, int value) {
  4284 void java_lang_StackFrameInfo::set_bci(oop element, int value) {
       
  4285   assert(value >= 0 && value < max_jushort, "must be a valid bci value");
  4219   element->int_field_put(_bci_offset, value);
  4286   element->int_field_put(_bci_offset, value);
  4220 }
  4287 }
  4221 
  4288 
  4222 void java_lang_LiveStackFrameInfo::set_monitors(oop element, oop value) {
  4289 void java_lang_LiveStackFrameInfo::set_monitors(oop element, oop value) {
  4223   element->obj_field_put(_monitors_offset, value);
  4290   element->obj_field_put(_monitors_offset, value);
  4311 #if INCLUDE_CDS
  4378 #if INCLUDE_CDS
  4312 void java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize_offsets(SerializeClosure* f) {
  4379 void java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize_offsets(SerializeClosure* f) {
  4313   AOS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
  4380   AOS_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
  4314 }
  4381 }
  4315 #endif
  4382 #endif
       
  4383 
       
  4384 #define INTEGER_CACHE_FIELDS_DO(macro) \
       
  4385   macro(_static_cache_offset, k, "cache", java_lang_Integer_array_signature, true)
       
  4386 
       
  4387 void java_lang_Integer_IntegerCache::compute_offsets(InstanceKlass *k) {
       
  4388   guarantee(k != NULL && k->is_initialized(), "must be loaded and initialized");
       
  4389   INTEGER_CACHE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
       
  4390 }
       
  4391 
       
  4392 objArrayOop java_lang_Integer_IntegerCache::cache(InstanceKlass *ik) {
       
  4393   oop base = ik->static_field_base_raw();
       
  4394   return objArrayOop(base->obj_field(_static_cache_offset));
       
  4395 }
       
  4396 
       
  4397 Symbol* java_lang_Integer_IntegerCache::symbol() {
       
  4398   return vmSymbols::java_lang_Integer_IntegerCache();
       
  4399 }
       
  4400 
       
  4401 #if INCLUDE_CDS
       
  4402 void java_lang_Integer_IntegerCache::serialize_offsets(SerializeClosure* f) {
       
  4403   INTEGER_CACHE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
       
  4404 }
       
  4405 #endif
       
  4406 #undef INTEGER_CACHE_FIELDS_DO
       
  4407 
       
  4408 jint java_lang_Integer::value(oop obj) {
       
  4409    jvalue v;
       
  4410    java_lang_boxing_object::get_value(obj, &v);
       
  4411    return v.i;
       
  4412 }
       
  4413 
       
  4414 #define LONG_CACHE_FIELDS_DO(macro) \
       
  4415   macro(_static_cache_offset, k, "cache", java_lang_Long_array_signature, true)
       
  4416 
       
  4417 void java_lang_Long_LongCache::compute_offsets(InstanceKlass *k) {
       
  4418   guarantee(k != NULL && k->is_initialized(), "must be loaded and initialized");
       
  4419   LONG_CACHE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
       
  4420 }
       
  4421 
       
  4422 objArrayOop java_lang_Long_LongCache::cache(InstanceKlass *ik) {
       
  4423   oop base = ik->static_field_base_raw();
       
  4424   return objArrayOop(base->obj_field(_static_cache_offset));
       
  4425 }
       
  4426 
       
  4427 Symbol* java_lang_Long_LongCache::symbol() {
       
  4428   return vmSymbols::java_lang_Long_LongCache();
       
  4429 }
       
  4430 
       
  4431 #if INCLUDE_CDS
       
  4432 void java_lang_Long_LongCache::serialize_offsets(SerializeClosure* f) {
       
  4433   LONG_CACHE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
       
  4434 }
       
  4435 #endif
       
  4436 #undef LONG_CACHE_FIELDS_DO
       
  4437 
       
  4438 jlong java_lang_Long::value(oop obj) {
       
  4439    jvalue v;
       
  4440    java_lang_boxing_object::get_value(obj, &v);
       
  4441    return v.j;
       
  4442 }
       
  4443 
       
  4444 #define CHARACTER_CACHE_FIELDS_DO(macro) \
       
  4445   macro(_static_cache_offset, k, "cache", java_lang_Character_array_signature, true)
       
  4446 
       
  4447 void java_lang_Character_CharacterCache::compute_offsets(InstanceKlass *k) {
       
  4448   guarantee(k != NULL && k->is_initialized(), "must be loaded and initialized");
       
  4449   CHARACTER_CACHE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
       
  4450 }
       
  4451 
       
  4452 objArrayOop java_lang_Character_CharacterCache::cache(InstanceKlass *ik) {
       
  4453   oop base = ik->static_field_base_raw();
       
  4454   return objArrayOop(base->obj_field(_static_cache_offset));
       
  4455 }
       
  4456 
       
  4457 Symbol* java_lang_Character_CharacterCache::symbol() {
       
  4458   return vmSymbols::java_lang_Character_CharacterCache();
       
  4459 }
       
  4460 
       
  4461 #if INCLUDE_CDS
       
  4462 void java_lang_Character_CharacterCache::serialize_offsets(SerializeClosure* f) {
       
  4463   CHARACTER_CACHE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
       
  4464 }
       
  4465 #endif
       
  4466 #undef CHARACTER_CACHE_FIELDS_DO
       
  4467 
       
  4468 jchar java_lang_Character::value(oop obj) {
       
  4469    jvalue v;
       
  4470    java_lang_boxing_object::get_value(obj, &v);
       
  4471    return v.c;
       
  4472 }
       
  4473 
       
  4474 #define SHORT_CACHE_FIELDS_DO(macro) \
       
  4475   macro(_static_cache_offset, k, "cache", java_lang_Short_array_signature, true)
       
  4476 
       
  4477 void java_lang_Short_ShortCache::compute_offsets(InstanceKlass *k) {
       
  4478   guarantee(k != NULL && k->is_initialized(), "must be loaded and initialized");
       
  4479   SHORT_CACHE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
       
  4480 }
       
  4481 
       
  4482 objArrayOop java_lang_Short_ShortCache::cache(InstanceKlass *ik) {
       
  4483   oop base = ik->static_field_base_raw();
       
  4484   return objArrayOop(base->obj_field(_static_cache_offset));
       
  4485 }
       
  4486 
       
  4487 Symbol* java_lang_Short_ShortCache::symbol() {
       
  4488   return vmSymbols::java_lang_Short_ShortCache();
       
  4489 }
       
  4490 
       
  4491 #if INCLUDE_CDS
       
  4492 void java_lang_Short_ShortCache::serialize_offsets(SerializeClosure* f) {
       
  4493   SHORT_CACHE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
       
  4494 }
       
  4495 #endif
       
  4496 #undef SHORT_CACHE_FIELDS_DO
       
  4497 
       
  4498 jshort java_lang_Short::value(oop obj) {
       
  4499    jvalue v;
       
  4500    java_lang_boxing_object::get_value(obj, &v);
       
  4501    return v.s;
       
  4502 }
       
  4503 
       
  4504 #define BYTE_CACHE_FIELDS_DO(macro) \
       
  4505   macro(_static_cache_offset, k, "cache", java_lang_Byte_array_signature, true)
       
  4506 
       
  4507 void java_lang_Byte_ByteCache::compute_offsets(InstanceKlass *k) {
       
  4508   guarantee(k != NULL && k->is_initialized(), "must be loaded and initialized");
       
  4509   BYTE_CACHE_FIELDS_DO(FIELD_COMPUTE_OFFSET);
       
  4510 }
       
  4511 
       
  4512 objArrayOop java_lang_Byte_ByteCache::cache(InstanceKlass *ik) {
       
  4513   oop base = ik->static_field_base_raw();
       
  4514   return objArrayOop(base->obj_field(_static_cache_offset));
       
  4515 }
       
  4516 
       
  4517 Symbol* java_lang_Byte_ByteCache::symbol() {
       
  4518   return vmSymbols::java_lang_Byte_ByteCache();
       
  4519 }
       
  4520 
       
  4521 #if INCLUDE_CDS
       
  4522 void java_lang_Byte_ByteCache::serialize_offsets(SerializeClosure* f) {
       
  4523   BYTE_CACHE_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
       
  4524 }
       
  4525 #endif
       
  4526 #undef BYTE_CACHE_FIELDS_DO
       
  4527 
       
  4528 jbyte java_lang_Byte::value(oop obj) {
       
  4529    jvalue v;
       
  4530    java_lang_boxing_object::get_value(obj, &v);
       
  4531    return v.b;
       
  4532 }
       
  4533 #define BOOLEAN_FIELDS_DO(macro) \
       
  4534   macro(_static_TRUE_offset, k, "TRUE", java_lang_Boolean_signature, true); \
       
  4535   macro(_static_FALSE_offset, k, "FALSE", java_lang_Boolean_signature, true)
       
  4536 
       
  4537 
       
  4538 void java_lang_Boolean::compute_offsets(InstanceKlass *k) {
       
  4539   guarantee(k != NULL && k->is_initialized(), "must be loaded and initialized");
       
  4540   BOOLEAN_FIELDS_DO(FIELD_COMPUTE_OFFSET);
       
  4541 }
       
  4542 
       
  4543 oop java_lang_Boolean::get_TRUE(InstanceKlass *ik) {
       
  4544   oop base = ik->static_field_base_raw();
       
  4545   return base->obj_field(_static_TRUE_offset);
       
  4546 }
       
  4547 
       
  4548 oop java_lang_Boolean::get_FALSE(InstanceKlass *ik) {
       
  4549   oop base = ik->static_field_base_raw();
       
  4550   return base->obj_field(_static_FALSE_offset);
       
  4551 }
       
  4552 
       
  4553 Symbol* java_lang_Boolean::symbol() {
       
  4554   return vmSymbols::java_lang_Boolean();
       
  4555 }
       
  4556 
       
  4557 #if INCLUDE_CDS
       
  4558 void java_lang_Boolean::serialize_offsets(SerializeClosure* f) {
       
  4559   BOOLEAN_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
       
  4560 }
       
  4561 #endif
       
  4562 #undef BOOLEAN_CACHE_FIELDS_DO
       
  4563 
       
  4564 jboolean java_lang_Boolean::value(oop obj) {
       
  4565    jvalue v;
       
  4566    java_lang_boxing_object::get_value(obj, &v);
       
  4567    return v.z;
       
  4568 }
  4316 
  4569 
  4317 static int member_offset(int hardcoded_offset) {
  4570 static int member_offset(int hardcoded_offset) {
  4318   return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
  4571   return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes();
  4319 }
  4572 }
  4320 
  4573 
  4351 
  4604 
  4352   // We have already called the compute_offsets() of the
  4605   // We have already called the compute_offsets() of the
  4353   // BASIC_JAVA_CLASSES_DO_PART1 classes (java_lang_String and java_lang_Class)
  4606   // BASIC_JAVA_CLASSES_DO_PART1 classes (java_lang_String and java_lang_Class)
  4354   // earlier inside SystemDictionary::resolve_well_known_classes()
  4607   // earlier inside SystemDictionary::resolve_well_known_classes()
  4355   BASIC_JAVA_CLASSES_DO_PART2(DO_COMPUTE_OFFSETS);
  4608   BASIC_JAVA_CLASSES_DO_PART2(DO_COMPUTE_OFFSETS);
  4356 
       
  4357   // generated interpreter code wants to know about the offsets we just computed:
       
  4358   AbstractAssembler::update_delayed_values();
       
  4359 }
  4609 }
  4360 
  4610 
  4361 #if INCLUDE_CDS
  4611 #if INCLUDE_CDS
  4362 #define DO_SERIALIZE_OFFSETS(k) k::serialize_offsets(soc);
  4612 #define DO_SERIALIZE_OFFSETS(k) k::serialize_offsets(soc);
  4363 
  4613