Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/javaClasses.hpp
32285 views
/*1* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP25#define SHARE_VM_CLASSFILE_JAVACLASSES_HPP2627#include "classfile/systemDictionary.hpp"28#include "jvmtifiles/jvmti.h"29#include "oops/oop.hpp"30#include "runtime/os.hpp"31#include "utilities/utf8.hpp"3233// Interface for manipulating the basic Java classes.34//35// All dependencies on layout of actual Java classes should be kept here.36// If the layout of any of the classes above changes the offsets must be adjusted.37//38// For most classes we hardwire the offsets for performance reasons. In certain39// cases (e.g. java.security.AccessControlContext) we compute the offsets at40// startup since the layout here differs between JDK1.2 and JDK1.3.41//42// Note that fields (static and non-static) are arranged with oops before non-oops43// on a per class basis. The offsets below have to reflect this ordering.44//45// When editing the layouts please update the check_offset verification code46// correspondingly. The names in the enums must be identical to the actual field47// names in order for the verification code to work.484950// Interface to java.lang.String objects5152class java_lang_String : AllStatic {53private:54static int value_offset;55static int offset_offset;56static int count_offset;57static int hash_offset;5859static bool initialized;6061static Handle basic_create(int length, TRAPS);6263static void set_offset(oop string, int offset) {64assert(initialized, "Must be initialized");65if (offset_offset > 0) {66string->int_field_put(offset_offset, offset);67}68}69static void set_count( oop string, int count) {70assert(initialized, "Must be initialized");71if (count_offset > 0) {72string->int_field_put(count_offset, count);73}74}7576public:77static void compute_offsets();7879// Instance creation80static Handle create_from_unicode(jchar* unicode, int len, TRAPS);81static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);82static Handle create_from_str(const char* utf8_str, TRAPS);83static oop create_oop_from_str(const char* utf8_str, TRAPS);84static Handle create_from_symbol(Symbol* symbol, TRAPS);85static Handle create_from_platform_dependent_str(const char* str, TRAPS);86static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);8788static bool has_offset_field() {89assert(initialized, "Must be initialized");90return (offset_offset > 0);91}9293static bool has_count_field() {94assert(initialized, "Must be initialized");95return (count_offset > 0);96}9798static bool has_hash_field() {99assert(initialized, "Must be initialized");100return (hash_offset > 0);101}102103static int value_offset_in_bytes() {104assert(initialized && (value_offset > 0), "Must be initialized");105return value_offset;106}107static int count_offset_in_bytes() {108assert(initialized && (count_offset > 0), "Must be initialized");109return count_offset;110}111static int offset_offset_in_bytes() {112assert(initialized && (offset_offset > 0), "Must be initialized");113return offset_offset;114}115static int hash_offset_in_bytes() {116assert(initialized && (hash_offset > 0), "Must be initialized");117return hash_offset;118}119120static void set_value(oop string, typeArrayOop buffer) {121assert(initialized && (value_offset > 0), "Must be initialized");122string->obj_field_put(value_offset, (oop)buffer);123}124static void set_hash(oop string, unsigned int hash) {125assert(initialized && (hash_offset > 0), "Must be initialized");126string->int_field_put(hash_offset, hash);127}128129// Accessors130static typeArrayOop value(oop java_string) {131assert(initialized && (value_offset > 0), "Must be initialized");132assert(is_instance(java_string), "must be java_string");133return (typeArrayOop) java_string->obj_field(value_offset);134}135static unsigned int hash(oop java_string) {136assert(initialized && (hash_offset > 0), "Must be initialized");137assert(is_instance(java_string), "must be java_string");138return java_string->int_field(hash_offset);139}140static int offset(oop java_string) {141assert(initialized, "Must be initialized");142assert(is_instance(java_string), "must be java_string");143if (offset_offset > 0) {144return java_string->int_field(offset_offset);145} else {146return 0;147}148}149static int length(oop java_string) {150assert(initialized, "Must be initialized");151assert(is_instance(java_string), "must be java_string");152if (count_offset > 0) {153return java_string->int_field(count_offset);154} else {155return ((typeArrayOop)java_string->obj_field(value_offset))->length();156}157}158static int utf8_length(oop java_string);159160// String converters161static char* as_utf8_string(oop java_string);162static char* as_utf8_string(oop java_string, char* buf, int buflen);163static char* as_utf8_string(oop java_string, int start, int len);164static char* as_platform_dependent_str(Handle java_string, TRAPS);165static jchar* as_unicode_string(oop java_string, int& length, TRAPS);166// produce an ascii string with all other values quoted using \u####167static char* as_quoted_ascii(oop java_string);168169// Compute the hash value for a java.lang.String object which would170// contain the characters passed in.171//172// As the hash value used by the String object itself, in173// String.hashCode(). This value is normally calculated in Java code174// in the String.hashCode method(), but is precomputed for String175// objects in the shared archive file.176// hash P(31) from Kernighan & Ritchie177//178// For this reason, THIS ALGORITHM MUST MATCH String.hashCode().179template <typename T> static unsigned int hash_code(T* s, int len) {180unsigned int h = 0;181while (len-- > 0) {182h = 31*h + (unsigned int) *s;183s++;184}185return h;186}187static unsigned int hash_code(oop java_string);188189// This is the string hash code used by the StringTable, which may be190// the same as String.hashCode or an alternate hash code.191static unsigned int hash_string(oop java_string);192193static bool equals(oop java_string, jchar* chars, int len);194static bool equals(oop str1, oop str2);195196// Conversion between '.' and '/' formats197static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }198static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }199200// Conversion201static Symbol* as_symbol(Handle java_string, TRAPS);202static Symbol* as_symbol_or_null(oop java_string);203204// Testers205static bool is_instance(oop obj) {206return obj != NULL && obj->klass() == SystemDictionary::String_klass();207}208209// Debugging210static void print(oop java_string, outputStream* st);211friend class JavaClasses;212};213214215// Interface to java.lang.Class objects216217#define CLASS_INJECTED_FIELDS(macro) \218macro(java_lang_Class, klass, intptr_signature, false) \219macro(java_lang_Class, array_klass, intptr_signature, false) \220macro(java_lang_Class, oop_size, int_signature, false) \221macro(java_lang_Class, static_oop_field_count, int_signature, false) \222macro(java_lang_Class, protection_domain, object_signature, false) \223macro(java_lang_Class, init_lock, object_signature, false) \224macro(java_lang_Class, signers, object_signature, false)225226class java_lang_Class : AllStatic {227friend class VMStructs;228229private:230// The fake offsets are added by the class loader when java.lang.Class is loaded231232static int _klass_offset;233static int _array_klass_offset;234235static int _oop_size_offset;236static int _static_oop_field_count_offset;237238static int _protection_domain_offset;239static int _init_lock_offset;240static int _signers_offset;241static int _class_loader_offset;242243static bool offsets_computed;244static int classRedefinedCount_offset;245246static GrowableArray<Klass*>* _fixup_mirror_list;247248static void set_init_lock(oop java_class, oop init_lock);249static void set_protection_domain(oop java_class, oop protection_domain);250static void set_class_loader(oop java_class, oop class_loader);251static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);252public:253static void compute_offsets();254255// Instance creation256static void create_mirror(KlassHandle k, Handle class_loader,257Handle protection_domain, TRAPS);258static void fixup_mirror(KlassHandle k, TRAPS);259static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);260// Conversion261static Klass* as_Klass(oop java_class);262static void set_klass(oop java_class, Klass* klass);263static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);264static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {265Klass* refk_oop = NULL;266BasicType result = as_BasicType(java_class, &refk_oop);267(*reference_klass) = KlassHandle(refk_oop);268return result;269}270static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);271static void print_signature(oop java_class, outputStream *st);272static const char* as_external_name(oop java_class);273// Testing274static bool is_instance(oop obj) {275return obj != NULL && obj->klass() == SystemDictionary::Class_klass();276}277static bool is_primitive(oop java_class);278static BasicType primitive_type(oop java_class);279static oop primitive_mirror(BasicType t);280// JVM_NewArray support281static Klass* array_klass(oop java_class);282static void set_array_klass(oop java_class, Klass* klass);283// compiler support for class operations284static int klass_offset_in_bytes() { return _klass_offset; }285static int array_klass_offset_in_bytes() { return _array_klass_offset; }286// Support for classRedefinedCount field287static int classRedefinedCount(oop the_class_mirror);288static void set_classRedefinedCount(oop the_class_mirror, int value);289290// Support for embedded per-class oops291static oop protection_domain(oop java_class);292static oop init_lock(oop java_class);293static objArrayOop signers(oop java_class);294static void set_signers(oop java_class, objArrayOop signers);295296static oop class_loader(oop java_class);297298static int oop_size(oop java_class);299static void set_oop_size(oop java_class, int size);300static int static_oop_field_count(oop java_class);301static void set_static_oop_field_count(oop java_class, int size);302303static GrowableArray<Klass*>* fixup_mirror_list() {304return _fixup_mirror_list;305}306static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {307_fixup_mirror_list = v;308}309// Debugging310friend class JavaClasses;311friend class InstanceKlass; // verification code accesses offsets312friend class ClassFileParser; // access to number_of_fake_fields313};314315// Interface to java.lang.Thread objects316317class java_lang_Thread : AllStatic {318private:319// Note that for this class the layout changed between JDK1.2 and JDK1.3,320// so we compute the offsets at startup rather than hard-wiring them.321static int _name_offset;322static int _group_offset;323static int _contextClassLoader_offset;324static int _inheritedAccessControlContext_offset;325static int _priority_offset;326static int _eetop_offset;327static int _daemon_offset;328static int _stillborn_offset;329static int _stackSize_offset;330static int _tid_offset;331static int _thread_status_offset;332static int _park_blocker_offset;333static int _park_event_offset ;334335static void compute_offsets();336337public:338// Instance creation339static oop create();340// Returns the JavaThread associated with the thread obj341static JavaThread* thread(oop java_thread);342// Set JavaThread for instance343static void set_thread(oop java_thread, JavaThread* thread);344// Name345static oop name(oop java_thread);346static void set_name(oop java_thread, oop name);347// Priority348static ThreadPriority priority(oop java_thread);349static void set_priority(oop java_thread, ThreadPriority priority);350// Thread group351static oop threadGroup(oop java_thread);352// Stillborn353static bool is_stillborn(oop java_thread);354static void set_stillborn(oop java_thread);355// Alive (NOTE: this is not really a field, but provides the correct356// definition without doing a Java call)357static bool is_alive(oop java_thread);358// Daemon359static bool is_daemon(oop java_thread);360static void set_daemon(oop java_thread);361// Context ClassLoader362static oop context_class_loader(oop java_thread);363// Control context364static oop inherited_access_control_context(oop java_thread);365// Stack size hint366static jlong stackSize(oop java_thread);367// Thread ID368static jlong thread_id(oop java_thread);369370// Blocker object responsible for thread parking371static oop park_blocker(oop java_thread);372373// Pointer to type-stable park handler, encoded as jlong.374// Should be set when apparently null375// For details, see unsafe.cpp Unsafe_Unpark376static jlong park_event(oop java_thread);377static bool set_park_event(oop java_thread, jlong ptr);378379// Java Thread Status for JVMTI and M&M use.380// This thread status info is saved in threadStatus field of381// java.lang.Thread java class.382enum ThreadStatus {383NEW = 0,384RUNNABLE = JVMTI_THREAD_STATE_ALIVE + // runnable / running385JVMTI_THREAD_STATE_RUNNABLE,386SLEEPING = JVMTI_THREAD_STATE_ALIVE + // Thread.sleep()387JVMTI_THREAD_STATE_WAITING +388JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +389JVMTI_THREAD_STATE_SLEEPING,390IN_OBJECT_WAIT = JVMTI_THREAD_STATE_ALIVE + // Object.wait()391JVMTI_THREAD_STATE_WAITING +392JVMTI_THREAD_STATE_WAITING_INDEFINITELY +393JVMTI_THREAD_STATE_IN_OBJECT_WAIT,394IN_OBJECT_WAIT_TIMED = JVMTI_THREAD_STATE_ALIVE + // Object.wait(long)395JVMTI_THREAD_STATE_WAITING +396JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +397JVMTI_THREAD_STATE_IN_OBJECT_WAIT,398PARKED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park()399JVMTI_THREAD_STATE_WAITING +400JVMTI_THREAD_STATE_WAITING_INDEFINITELY +401JVMTI_THREAD_STATE_PARKED,402PARKED_TIMED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park(long)403JVMTI_THREAD_STATE_WAITING +404JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +405JVMTI_THREAD_STATE_PARKED,406BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE + // (re-)entering a synchronization block407JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,408TERMINATED = JVMTI_THREAD_STATE_TERMINATED409};410// Write thread status info to threadStatus field of java.lang.Thread.411static void set_thread_status(oop java_thread_oop, ThreadStatus status);412// Read thread status info from threadStatus field of java.lang.Thread.413static ThreadStatus get_thread_status(oop java_thread_oop);414415static const char* thread_status_name(oop java_thread_oop);416417// Debugging418friend class JavaClasses;419};420421// Interface to java.lang.ThreadGroup objects422423class java_lang_ThreadGroup : AllStatic {424private:425static int _parent_offset;426static int _name_offset;427static int _threads_offset;428static int _groups_offset;429static int _maxPriority_offset;430static int _destroyed_offset;431static int _daemon_offset;432static int _vmAllowSuspension_offset;433static int _nthreads_offset;434static int _ngroups_offset;435436static void compute_offsets();437438public:439// parent ThreadGroup440static oop parent(oop java_thread_group);441// name442static typeArrayOop name(oop java_thread_group);443// ("name as oop" accessor is not necessary)444// Number of threads in group445static int nthreads(oop java_thread_group);446// threads447static objArrayOop threads(oop java_thread_group);448// Number of threads in group449static int ngroups(oop java_thread_group);450// groups451static objArrayOop groups(oop java_thread_group);452// maxPriority in group453static ThreadPriority maxPriority(oop java_thread_group);454// Destroyed455static bool is_destroyed(oop java_thread_group);456// Daemon457static bool is_daemon(oop java_thread_group);458// vmAllowSuspension459static bool is_vmAllowSuspension(oop java_thread_group);460// Debugging461friend class JavaClasses;462};463464465466// Interface to java.lang.Throwable objects467468class java_lang_Throwable: AllStatic {469friend class BacktraceBuilder;470471private:472// Offsets473enum {474hc_backtrace_offset = 0,475hc_detailMessage_offset = 1,476hc_cause_offset = 2, // New since 1.4477hc_stackTrace_offset = 3 // New since 1.4478};479enum {480hc_static_unassigned_stacktrace_offset = 0 // New since 1.7481};482// Trace constants483enum {484trace_methods_offset = 0,485trace_bcis_offset = 1,486trace_mirrors_offset = 2,487trace_cprefs_offset = 3,488trace_next_offset = 4,489trace_size = 5,490trace_chunk_size = 32491};492493static int backtrace_offset;494static int detailMessage_offset;495static int cause_offset;496static int stackTrace_offset;497static int static_unassigned_stacktrace_offset;498499// Printing500static char* print_stack_element_to_buffer(Handle mirror, int method, int version, int bci, int cpref);501// StackTrace (programmatic access, new since 1.4)502static void clear_stacktrace(oop throwable);503// No stack trace available504static const char* no_stack_trace_message();505// Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)506static void set_stacktrace(oop throwable, oop st_element_array);507static oop unassigned_stacktrace();508509public:510// Backtrace511static oop backtrace(oop throwable);512static void set_backtrace(oop throwable, oop value);513// Needed by JVMTI to filter out this internal field.514static int get_backtrace_offset() { return backtrace_offset;}515static int get_detailMessage_offset() { return detailMessage_offset;}516// Message517static oop message(oop throwable);518static oop message(Handle throwable);519static void set_message(oop throwable, oop value);520static Symbol* detail_message(oop throwable);521static void print_stack_element(outputStream *st, Handle mirror, int method,522int version, int bci, int cpref);523static void print_stack_element(outputStream *st, methodHandle method, int bci);524static void print_stack_usage(Handle stream);525526// Allocate space for backtrace (created but stack trace not filled in)527static void allocate_backtrace(Handle throwable, TRAPS);528// Fill in current stack trace for throwable with preallocated backtrace (no GC)529static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);530// Fill in current stack trace, can cause GC531static void fill_in_stack_trace(Handle throwable, methodHandle method, TRAPS);532static void fill_in_stack_trace(Handle throwable, methodHandle method = methodHandle());533// Programmatic access to stack trace534static oop get_stack_trace_element(oop throwable, int index, TRAPS);535static int get_stack_trace_depth(oop throwable, TRAPS);536// Printing537static void print(oop throwable, outputStream* st);538static void print(Handle throwable, outputStream* st);539static void print_stack_trace(oop throwable, outputStream* st);540// Debugging541friend class JavaClasses;542};543544545// Interface to java.lang.reflect.AccessibleObject objects546547class java_lang_reflect_AccessibleObject: AllStatic {548private:549// Note that to reduce dependencies on the JDK we compute these550// offsets at run-time.551static int override_offset;552553static void compute_offsets();554555public:556// Accessors557static jboolean override(oop reflect);558static void set_override(oop reflect, jboolean value);559560// Debugging561friend class JavaClasses;562};563564565// Interface to java.lang.reflect.Method objects566567class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {568private:569// Note that to reduce dependencies on the JDK we compute these570// offsets at run-time.571static int clazz_offset;572static int name_offset;573static int returnType_offset;574static int parameterTypes_offset;575static int exceptionTypes_offset;576static int slot_offset;577static int modifiers_offset;578static int signature_offset;579static int annotations_offset;580static int parameter_annotations_offset;581static int annotation_default_offset;582static int type_annotations_offset;583584static void compute_offsets();585586public:587// Allocation588static Handle create(TRAPS);589590// Accessors591static oop clazz(oop reflect);592static void set_clazz(oop reflect, oop value);593594static oop name(oop method);595static void set_name(oop method, oop value);596597static oop return_type(oop method);598static void set_return_type(oop method, oop value);599600static oop parameter_types(oop method);601static void set_parameter_types(oop method, oop value);602603static oop exception_types(oop method);604static void set_exception_types(oop method, oop value);605606static int slot(oop reflect);607static void set_slot(oop reflect, int value);608609static int modifiers(oop method);610static void set_modifiers(oop method, int value);611612static bool has_signature_field();613static oop signature(oop method);614static void set_signature(oop method, oop value);615616static bool has_annotations_field();617static oop annotations(oop method);618static void set_annotations(oop method, oop value);619620static bool has_parameter_annotations_field();621static oop parameter_annotations(oop method);622static void set_parameter_annotations(oop method, oop value);623624static bool has_annotation_default_field();625static oop annotation_default(oop method);626static void set_annotation_default(oop method, oop value);627628static bool has_type_annotations_field();629static oop type_annotations(oop method);630static void set_type_annotations(oop method, oop value);631632// Debugging633friend class JavaClasses;634};635636637// Interface to java.lang.reflect.Constructor objects638639class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {640private:641// Note that to reduce dependencies on the JDK we compute these642// offsets at run-time.643static int clazz_offset;644static int parameterTypes_offset;645static int exceptionTypes_offset;646static int slot_offset;647static int modifiers_offset;648static int signature_offset;649static int annotations_offset;650static int parameter_annotations_offset;651static int type_annotations_offset;652653static void compute_offsets();654655public:656// Allocation657static Handle create(TRAPS);658659// Accessors660static oop clazz(oop reflect);661static void set_clazz(oop reflect, oop value);662663static oop parameter_types(oop constructor);664static void set_parameter_types(oop constructor, oop value);665666static oop exception_types(oop constructor);667static void set_exception_types(oop constructor, oop value);668669static int slot(oop reflect);670static void set_slot(oop reflect, int value);671672static int modifiers(oop constructor);673static void set_modifiers(oop constructor, int value);674675static bool has_signature_field();676static oop signature(oop constructor);677static void set_signature(oop constructor, oop value);678679static bool has_annotations_field();680static oop annotations(oop constructor);681static void set_annotations(oop constructor, oop value);682683static bool has_parameter_annotations_field();684static oop parameter_annotations(oop method);685static void set_parameter_annotations(oop method, oop value);686687static bool has_type_annotations_field();688static oop type_annotations(oop constructor);689static void set_type_annotations(oop constructor, oop value);690691// Debugging692friend class JavaClasses;693};694695696// Interface to java.lang.reflect.Field objects697698class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {699private:700// Note that to reduce dependencies on the JDK we compute these701// offsets at run-time.702static int clazz_offset;703static int name_offset;704static int type_offset;705static int slot_offset;706static int modifiers_offset;707static int signature_offset;708static int annotations_offset;709static int type_annotations_offset;710711static void compute_offsets();712713public:714// Allocation715static Handle create(TRAPS);716717// Accessors718static oop clazz(oop reflect);719static void set_clazz(oop reflect, oop value);720721static oop name(oop field);722static void set_name(oop field, oop value);723724static oop type(oop field);725static void set_type(oop field, oop value);726727static int slot(oop reflect);728static void set_slot(oop reflect, int value);729730static int modifiers(oop field);731static void set_modifiers(oop field, int value);732733static bool has_signature_field();734static oop signature(oop constructor);735static void set_signature(oop constructor, oop value);736737static bool has_annotations_field();738static oop annotations(oop constructor);739static void set_annotations(oop constructor, oop value);740741static bool has_parameter_annotations_field();742static oop parameter_annotations(oop method);743static void set_parameter_annotations(oop method, oop value);744745static bool has_annotation_default_field();746static oop annotation_default(oop method);747static void set_annotation_default(oop method, oop value);748749static bool has_type_annotations_field();750static oop type_annotations(oop field);751static void set_type_annotations(oop field, oop value);752753// Debugging754friend class JavaClasses;755};756757class java_lang_reflect_Parameter {758private:759// Note that to reduce dependencies on the JDK we compute these760// offsets at run-time.761static int name_offset;762static int modifiers_offset;763static int index_offset;764static int executable_offset;765766static void compute_offsets();767768public:769// Allocation770static Handle create(TRAPS);771772// Accessors773static oop name(oop field);774static void set_name(oop field, oop value);775776static int index(oop reflect);777static void set_index(oop reflect, int value);778779static int modifiers(oop reflect);780static void set_modifiers(oop reflect, int value);781782static oop executable(oop constructor);783static void set_executable(oop constructor, oop value);784785friend class JavaClasses;786};787788// Interface to sun.reflect.ConstantPool objects789class sun_reflect_ConstantPool {790private:791// Note that to reduce dependencies on the JDK we compute these792// offsets at run-time.793static int _oop_offset;794795static void compute_offsets();796797public:798// Allocation799static Handle create(TRAPS);800801// Accessors802static void set_cp(oop reflect, ConstantPool* value);803static int oop_offset() {804return _oop_offset;805}806807static ConstantPool* get_cp(oop reflect);808809// Debugging810friend class JavaClasses;811};812813// Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects814class sun_reflect_UnsafeStaticFieldAccessorImpl {815private:816static int _base_offset;817static void compute_offsets();818819public:820static int base_offset() {821return _base_offset;822}823824// Debugging825friend class JavaClasses;826};827828// Interface to java.lang primitive type boxing objects:829// - java.lang.Boolean830// - java.lang.Character831// - java.lang.Float832// - java.lang.Double833// - java.lang.Byte834// - java.lang.Short835// - java.lang.Integer836// - java.lang.Long837838// This could be separated out into 8 individual classes.839840class java_lang_boxing_object: AllStatic {841private:842enum {843hc_value_offset = 0844};845static int value_offset;846static int long_value_offset;847848static oop initialize_and_allocate(BasicType type, TRAPS);849public:850// Allocation. Returns a boxed value, or NULL for invalid type.851static oop create(BasicType type, jvalue* value, TRAPS);852// Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.853static BasicType get_value(oop box, jvalue* value);854static BasicType set_value(oop box, jvalue* value);855static BasicType basic_type(oop box);856static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }857static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }858static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }859static void print(BasicType type, jvalue* value, outputStream* st);860861static int value_offset_in_bytes(BasicType type) {862return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :863value_offset;864}865866// Debugging867friend class JavaClasses;868};869870871872// Interface to java.lang.ref.Reference objects873874class java_lang_ref_Reference: AllStatic {875public:876enum {877hc_referent_offset = 0,878hc_queue_offset = 1,879hc_next_offset = 2,880hc_discovered_offset = 3 // Is not last, see SoftRefs.881};882enum {883hc_static_lock_offset = 0,884hc_static_pending_offset = 1885};886887static int referent_offset;888static int queue_offset;889static int next_offset;890static int discovered_offset;891static int static_lock_offset;892static int static_pending_offset;893static int number_of_fake_oop_fields;894895// Accessors896static oop referent(oop ref) {897return ref->obj_field(referent_offset);898}899static void set_referent(oop ref, oop value) {900ref->obj_field_put(referent_offset, value);901}902static void set_referent_raw(oop ref, oop value) {903ref->obj_field_put_raw(referent_offset, value);904}905static HeapWord* referent_addr(oop ref) {906return ref->obj_field_addr<HeapWord>(referent_offset);907}908static oop next(oop ref) {909return ref->obj_field(next_offset);910}911static void set_next(oop ref, oop value) {912ref->obj_field_put(next_offset, value);913}914static void set_next_raw(oop ref, oop value) {915ref->obj_field_put_raw(next_offset, value);916}917static HeapWord* next_addr(oop ref) {918return ref->obj_field_addr<HeapWord>(next_offset);919}920static oop discovered(oop ref) {921return ref->obj_field(discovered_offset);922}923static void set_discovered(oop ref, oop value) {924ref->obj_field_put(discovered_offset, value);925}926static void set_discovered_raw(oop ref, oop value) {927ref->obj_field_put_raw(discovered_offset, value);928}929static HeapWord* discovered_addr(oop ref) {930return ref->obj_field_addr<HeapWord>(discovered_offset);931}932static inline oop queue(oop ref) {933return ref->obj_field(queue_offset);934}935static inline void set_queue(oop ref, oop value) {936return ref->obj_field_put(queue_offset, value);937}938// Accessors for statics939static oop pending_list_lock();940static oop pending_list();941942static HeapWord* pending_list_lock_addr();943static HeapWord* pending_list_addr();944};945946947// Interface to java.lang.ref.SoftReference objects948949class java_lang_ref_SoftReference: public java_lang_ref_Reference {950public:951enum {952// The timestamp is a long field and may need to be adjusted for alignment.953hc_timestamp_offset = hc_discovered_offset + 1954};955enum {956hc_static_clock_offset = 0957};958959static int timestamp_offset;960static int static_clock_offset;961962// Accessors963static jlong timestamp(oop ref);964965// Accessors for statics966static jlong clock();967static void set_clock(jlong value);968};969970971// Interface to java.lang.ref.ReferenceQueue objects972973class java_lang_ref_ReferenceQueue: public AllStatic {974public:975static int static_NULL_queue_offset;976static int static_ENQUEUED_queue_offset;977978// Accessors979static oop NULL_queue();980static oop ENQUEUED_queue();981982static void compute_offsets();983};984985// Interface to java.lang.invoke.MethodHandle objects986987class MethodHandleEntry;988989class java_lang_invoke_MethodHandle: AllStatic {990friend class JavaClasses;991992private:993static int _type_offset; // the MethodType of this MH994static int _form_offset; // the LambdaForm of this MH995996static void compute_offsets();997998public:999// Accessors1000static oop type(oop mh);1001static void set_type(oop mh, oop mtype);10021003static oop form(oop mh);1004static void set_form(oop mh, oop lform);10051006// Testers1007static bool is_subclass(Klass* klass) {1008return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());1009}1010static bool is_instance(oop obj) {1011return obj != NULL && is_subclass(obj->klass());1012}10131014// Accessors for code generation:1015static int type_offset_in_bytes() { return _type_offset; }1016static int form_offset_in_bytes() { return _form_offset; }1017};10181019// Interface to java.lang.invoke.DirectMethodHandle objects10201021class java_lang_invoke_DirectMethodHandle: AllStatic {1022friend class JavaClasses;10231024private:1025static int _member_offset; // the MemberName of this DMH10261027static void compute_offsets();10281029public:1030// Accessors1031static oop member(oop mh);10321033// Testers1034static bool is_subclass(Klass* klass) {1035return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());1036}1037static bool is_instance(oop obj) {1038return obj != NULL && is_subclass(obj->klass());1039}10401041// Accessors for code generation:1042static int member_offset_in_bytes() { return _member_offset; }1043};10441045// Interface to java.lang.invoke.LambdaForm objects1046// (These are a private interface for managing adapter code generation.)10471048class java_lang_invoke_LambdaForm: AllStatic {1049friend class JavaClasses;10501051private:1052static int _vmentry_offset; // type is MemberName10531054static void compute_offsets();10551056public:1057// Accessors1058static oop vmentry(oop lform);1059static void set_vmentry(oop lform, oop invoker);10601061// Testers1062static bool is_subclass(Klass* klass) {1063return SystemDictionary::LambdaForm_klass() != NULL &&1064klass->is_subclass_of(SystemDictionary::LambdaForm_klass());1065}1066static bool is_instance(oop obj) {1067return obj != NULL && is_subclass(obj->klass());1068}10691070// Accessors for code generation:1071static int vmentry_offset_in_bytes() { return _vmentry_offset; }1072};107310741075// Interface to java.lang.invoke.MemberName objects1076// (These are a private interface for Java code to query the class hierarchy.)10771078#define MEMBERNAME_INJECTED_FIELDS(macro) \1079macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \1080macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false) \1081macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)10821083class java_lang_invoke_MemberName: AllStatic {1084friend class JavaClasses;10851086private:1087// From java.lang.invoke.MemberName:1088// private Class<?> clazz; // class in which the method is defined1089// private String name; // may be null if not yet materialized1090// private Object type; // may be null if not yet materialized1091// private int flags; // modifier bits; see reflect.Modifier1092// private intptr vmtarget; // VM-specific target value1093// private intptr_t vmindex; // member index within class or interface1094static int _clazz_offset;1095static int _name_offset;1096static int _type_offset;1097static int _flags_offset;1098static int _vmtarget_offset;1099static int _vmloader_offset;1100static int _vmindex_offset;11011102static void compute_offsets();11031104public:1105// Accessors1106static oop clazz(oop mname);1107static void set_clazz(oop mname, oop clazz);11081109static oop type(oop mname);1110static void set_type(oop mname, oop type);11111112static oop name(oop mname);1113static void set_name(oop mname, oop name);11141115static int flags(oop mname);1116static void set_flags(oop mname, int flags);11171118static Metadata* vmtarget(oop mname);1119static void set_vmtarget(oop mname, Metadata* target);11201121static intptr_t vmindex(oop mname);1122static void set_vmindex(oop mname, intptr_t index);11231124// Testers1125static bool is_subclass(Klass* klass) {1126return klass->is_subclass_of(SystemDictionary::MemberName_klass());1127}1128static bool is_instance(oop obj) {1129return obj != NULL && is_subclass(obj->klass());1130}11311132static bool is_method(oop obj);11331134// Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):1135enum {1136MN_IS_METHOD = 0x00010000, // method (not constructor)1137MN_IS_CONSTRUCTOR = 0x00020000, // constructor1138MN_IS_FIELD = 0x00040000, // field1139MN_IS_TYPE = 0x00080000, // nested type1140MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected1141MN_REFERENCE_KIND_SHIFT = 24, // refKind1142MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,1143// The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:1144MN_SEARCH_SUPERCLASSES = 0x00100000, // walk super classes1145MN_SEARCH_INTERFACES = 0x00200000 // walk implemented interfaces1146};11471148// Accessors for code generation:1149static int clazz_offset_in_bytes() { return _clazz_offset; }1150static int type_offset_in_bytes() { return _type_offset; }1151static int name_offset_in_bytes() { return _name_offset; }1152static int flags_offset_in_bytes() { return _flags_offset; }1153static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }1154static int vmindex_offset_in_bytes() { return _vmindex_offset; }11551156static bool equals(oop mt1, oop mt2);1157};115811591160// Interface to java.lang.invoke.MethodType objects11611162class java_lang_invoke_MethodType: AllStatic {1163friend class JavaClasses;11641165private:1166static int _rtype_offset;1167static int _ptypes_offset;11681169static void compute_offsets();11701171public:1172// Accessors1173static oop rtype(oop mt);1174static objArrayOop ptypes(oop mt);11751176static oop ptype(oop mt, int index);1177static int ptype_count(oop mt);11781179static int ptype_slot_count(oop mt); // extra counts for long/double1180static int rtype_slot_count(oop mt); // extra counts for long/double11811182static Symbol* as_signature(oop mt, bool intern_if_not_found, TRAPS);1183static void print_signature(oop mt, outputStream* st);11841185static bool is_instance(oop obj) {1186return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();1187}11881189static bool equals(oop mt1, oop mt2);11901191// Accessors for code generation:1192static int rtype_offset_in_bytes() { return _rtype_offset; }1193static int ptypes_offset_in_bytes() { return _ptypes_offset; }1194};119511961197// Interface to java.lang.invoke.CallSite objects11981199class java_lang_invoke_CallSite: AllStatic {1200friend class JavaClasses;12011202private:1203static int _target_offset;12041205static void compute_offsets();12061207public:1208// Accessors1209static oop target( oop site) { return site->obj_field( _target_offset); }1210static void set_target( oop site, oop target) { site->obj_field_put( _target_offset, target); }12111212static volatile oop target_volatile(oop site) { return oop((oopDesc *)(site->obj_field_volatile(_target_offset))); }1213static void set_target_volatile(oop site, oop target) { site->obj_field_put_volatile(_target_offset, target); }12141215// Testers1216static bool is_subclass(Klass* klass) {1217return klass->is_subclass_of(SystemDictionary::CallSite_klass());1218}1219static bool is_instance(oop obj) {1220return obj != NULL && is_subclass(obj->klass());1221}12221223// Accessors for code generation:1224static int target_offset_in_bytes() { return _target_offset; }1225};122612271228// Interface to java.security.AccessControlContext objects12291230class java_security_AccessControlContext: AllStatic {1231private:1232// Note that for this class the layout changed between JDK1.2 and JDK1.3,1233// so we compute the offsets at startup rather than hard-wiring them.1234static int _context_offset;1235static int _privilegedContext_offset;1236static int _isPrivileged_offset;1237static int _isAuthorized_offset;12381239static void compute_offsets();1240public:1241static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);12421243static bool is_authorized(Handle context);12441245// Debugging/initialization1246friend class JavaClasses;1247};124812491250// Interface to java.lang.ClassLoader objects12511252#define CLASSLOADER_INJECTED_FIELDS(macro) \1253macro(java_lang_ClassLoader, loader_data, intptr_signature, false)12541255class java_lang_ClassLoader : AllStatic {1256private:1257// The fake offsets are added by the class loader when java.lang.Class is loaded1258enum {1259hc_parent_offset = 01260};1261static int _loader_data_offset;1262static bool offsets_computed;1263static int parent_offset;1264static int parallelCapable_offset;12651266public:1267static void compute_offsets();12681269static ClassLoaderData** loader_data_addr(oop loader);1270static ClassLoaderData* loader_data(oop loader);12711272static oop parent(oop loader);1273static bool isAncestor(oop loader, oop cl);12741275// Support for parallelCapable field1276static bool parallelCapable(oop the_class_mirror);12771278static bool is_trusted_loader(oop loader);12791280// Fix for 44741721281static oop non_reflection_class_loader(oop loader);12821283// Testers1284static bool is_subclass(Klass* klass) {1285return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());1286}1287static bool is_instance(oop obj) {1288return obj != NULL && is_subclass(obj->klass());1289}12901291// Debugging1292friend class JavaClasses;1293friend class ClassFileParser; // access to number_of_fake_fields1294};129512961297// Interface to java.lang.System objects12981299class java_lang_System : AllStatic {1300private:1301enum {1302hc_static_in_offset = 0,1303hc_static_out_offset = 1,1304hc_static_err_offset = 2,1305hc_static_security_offset = 31306};13071308static int static_in_offset;1309static int static_out_offset;1310static int static_err_offset;1311static int static_security_offset;13121313public:1314static int in_offset_in_bytes();1315static int out_offset_in_bytes();1316static int err_offset_in_bytes();13171318static bool has_security_manager();13191320// Debugging1321friend class JavaClasses;1322};132313241325// Interface to java.lang.StackTraceElement objects13261327class java_lang_StackTraceElement: AllStatic {1328private:1329enum {1330hc_declaringClass_offset = 0,1331hc_methodName_offset = 1,1332hc_fileName_offset = 2,1333hc_lineNumber_offset = 31334};13351336static int declaringClass_offset;1337static int methodName_offset;1338static int fileName_offset;1339static int lineNumber_offset;13401341public:1342// Setters1343static void set_declaringClass(oop element, oop value);1344static void set_methodName(oop element, oop value);1345static void set_fileName(oop element, oop value);1346static void set_lineNumber(oop element, int value);13471348// Create an instance of StackTraceElement1349static oop create(Handle mirror, int method, int version, int bci, int cpref, TRAPS);1350static oop create(methodHandle method, int bci, TRAPS);13511352// Debugging1353friend class JavaClasses;1354};135513561357// Interface to java.lang.AssertionStatusDirectives objects13581359class java_lang_AssertionStatusDirectives: AllStatic {1360private:1361enum {1362hc_classes_offset,1363hc_classEnabled_offset,1364hc_packages_offset,1365hc_packageEnabled_offset,1366hc_deflt_offset1367};13681369static int classes_offset;1370static int classEnabled_offset;1371static int packages_offset;1372static int packageEnabled_offset;1373static int deflt_offset;13741375public:1376// Setters1377static void set_classes(oop obj, oop val);1378static void set_classEnabled(oop obj, oop val);1379static void set_packages(oop obj, oop val);1380static void set_packageEnabled(oop obj, oop val);1381static void set_deflt(oop obj, bool val);1382// Debugging1383friend class JavaClasses;1384};138513861387class java_nio_Buffer: AllStatic {1388private:1389static int _limit_offset;13901391public:1392static int limit_offset();1393static void compute_offsets();1394};13951396class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {1397private:1398static int _owner_offset;1399public:1400static void initialize(TRAPS);1401static oop get_owner_threadObj(oop obj);1402};14031404// Use to declare fields that need to be injected into Java classes1405// for the JVM to use. The name_index and signature_index are1406// declared in vmSymbols. The may_be_java flag is used to declare1407// fields that might already exist in Java but should be injected if1408// they don't. Otherwise the field is unconditionally injected and1409// the JVM uses the injected one. This is to ensure that name1410// collisions don't occur. In general may_be_java should be false1411// unless there's a good reason.14121413class InjectedField {1414public:1415const SystemDictionary::WKID klass_id;1416const vmSymbols::SID name_index;1417const vmSymbols::SID signature_index;1418const bool may_be_java;141914201421Klass* klass() const { return SystemDictionary::well_known_klass(klass_id); }1422Symbol* name() const { return lookup_symbol(name_index); }1423Symbol* signature() const { return lookup_symbol(signature_index); }14241425int compute_offset();14261427// Find the Symbol for this index1428static Symbol* lookup_symbol(int symbol_index) {1429return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);1430}1431};14321433#define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \1434klass##_##name##_enum,14351436#define ALL_INJECTED_FIELDS(macro) \1437CLASS_INJECTED_FIELDS(macro) \1438CLASSLOADER_INJECTED_FIELDS(macro) \1439MEMBERNAME_INJECTED_FIELDS(macro)14401441// Interface to hard-coded offset checking14421443class JavaClasses : AllStatic {1444private:14451446static InjectedField _injected_fields[];14471448static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;1449static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;1450static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;14511452public:1453enum InjectedFieldID {1454ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)1455MAX_enum1456};14571458static int compute_injected_offset(InjectedFieldID id);14591460static void compute_hard_coded_offsets();1461static void compute_offsets();1462static void check_offsets() PRODUCT_RETURN;14631464static InjectedField* get_injected(Symbol* class_name, int* field_count);1465};14661467#undef DECLARE_INJECTED_FIELD_ENUM14681469#endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP147014711472