/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "classfile/systemDictionary.hpp"
#include "jvmtifiles/jvmti.h"
// Interface for manipulating the basic Java classes.
//
// All dependencies on layout of actual Java classes should be kept here.
// If the layout of any of the classes above changes the offsets must be adjusted.
//
// For most classes we hardwire the offsets for performance reasons. In certain
// cases (e.g. java.security.AccessControlContext) we compute the offsets at
// startup since the layout here differs between JDK1.2 and JDK1.3.
//
// Note that fields (static and non-static) are arranged with oops before non-oops
// on a per class basis. The offsets below have to reflect this ordering.
//
// When editing the layouts please update the check_offset verification code
// correspondingly. The names in the enums must be identical to the actual field
// names in order for the verification code to work.
// Interface to java.lang.String objects
private:
static int value_offset;
static int offset_offset;
static int count_offset;
static int hash_offset;
static bool initialized;
}
if (offset_offset > 0) {
}
}
if (count_offset > 0) {
}
}
public:
static void compute_offsets();
// Instance creation
static bool has_offset_field() {
return (offset_offset > 0);
}
static bool has_count_field() {
return (count_offset > 0);
}
static bool has_hash_field() {
return (hash_offset > 0);
}
static int value_offset_in_bytes() {
return value_offset;
}
static int count_offset_in_bytes() {
return count_offset;
}
static int offset_offset_in_bytes() {
return offset_offset;
}
static int hash_offset_in_bytes() {
return hash_offset;
}
// Accessors
}
if (offset_offset > 0) {
} else {
return 0;
}
}
if (count_offset > 0) {
} else {
}
}
// String converters
// Compute the hash value for a java.lang.String object which would
// contain the characters passed in.
//
// As the hash value used by the String object itself, in
// String.hashCode(). This value is normally calculated in Java code
// in the String.hashCode method(), but is precomputed for String
// objects in the shared archive file.
// hash P(31) from Kernighan & Ritchie
//
// For this reason, THIS ALGORITHM MUST MATCH String.toHash().
unsigned int h = 0;
while (len-- > 0) {
h = 31*h + (unsigned int) *s;
s++;
}
return h;
}
// This is the string hash code used by the StringTable, which may be
// the same as String.toHash or an alternate hash code.
// Conversion between '.' and '/' formats
static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
// Conversion
// Testers
}
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.Class objects
friend class VMStructs;
private:
// The fake offsets are added by the class loader when java.lang.Class is loaded
static int _klass_offset;
static int _resolved_constructor_offset;
static int _array_klass_offset;
static int _oop_size_offset;
static int _static_oop_field_count_offset;
static bool offsets_computed;
static int classRedefinedCount_offset;
public:
static void compute_offsets();
// Instance creation
// Conversion
return result;
}
// Testing
}
// JVM_NewInstance support
// JVM_NewArray support
// compiler support for class operations
// Support for classRedefinedCount field
// Debugging
friend class JavaClasses;
friend class instanceKlass; // verification code accesses offsets
friend class ClassFileParser; // access to number_of_fake_fields
};
// Interface to java.lang.Thread objects
private:
// Note that for this class the layout changed between JDK1.2 and JDK1.3,
// so we compute the offsets at startup rather than hard-wiring them.
static int _name_offset;
static int _group_offset;
static int _contextClassLoader_offset;
static int _inheritedAccessControlContext_offset;
static int _priority_offset;
static int _eetop_offset;
static int _daemon_offset;
static int _stillborn_offset;
static int _stackSize_offset;
static int _tid_offset;
static int _thread_status_offset;
static int _park_blocker_offset;
static int _park_event_offset ;
static void compute_offsets();
public:
// Instance creation
// Returns the JavaThread associated with the thread obj
// Set JavaThread for instance
// Name
// Priority
// Thread group
// Stillborn
// Alive (NOTE: this is not really a field, but provides the correct
// definition without doing a Java call)
// Daemon
// Context ClassLoader
// Control context
// Stack size hint
// Thread ID
// Blocker object responsible for thread parking
// Pointer to type-stable park handler, encoded as jlong.
// Should be set when apparently null
// For details, see unsafe.cpp Unsafe_Unpark
// Java Thread Status for JVMTI and M&M use.
// This thread status info is saved in threadStatus field of
// java.lang.Thread java class.
enum ThreadStatus {
NEW = 0,
};
// Write thread status info to threadStatus field of java.lang.Thread.
// Read thread status info from threadStatus field of java.lang.Thread.
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.ThreadGroup objects
private:
static int _parent_offset;
static int _name_offset;
static int _threads_offset;
static int _groups_offset;
static int _maxPriority_offset;
static int _destroyed_offset;
static int _daemon_offset;
static int _vmAllowSuspension_offset;
static int _nthreads_offset;
static int _ngroups_offset;
static void compute_offsets();
public:
// parent ThreadGroup
// name
// ("name as oop" accessor is not necessary)
// Number of threads in group
// threads
// Number of threads in group
// groups
// maxPriority in group
// Destroyed
// Daemon
// vmAllowSuspension
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.Throwable objects
friend class BacktraceBuilder;
private:
// Offsets
enum {
hc_backtrace_offset = 0,
};
enum {
};
// Trace constants
enum {
trace_methods_offset = 0,
};
static int backtrace_offset;
static int detailMessage_offset;
static int cause_offset;
static int stackTrace_offset;
static int static_unassigned_stacktrace_offset;
// Printing
// StackTrace (programmatic access, new since 1.4)
// No stack trace available
static const char* no_stack_trace_message();
// Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
static oop unassigned_stacktrace();
public:
// Backtrace
// Needed by JVMTI to filter out this internal field.
// Message
// Print stack trace stored in exception by call-back to Java
// Note: this is no longer used in Merlin, but we still suppport
// it for compatibility.
// Allocate space for backtrace (created but stack trace not filled in)
// Fill in current stack trace for throwable with preallocated backtrace (no GC)
// Fill in current stack trace, can cause GC
// Programmatic access to stack trace
// Printing
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.reflect.AccessibleObject objects
private:
// Note that to reduce dependencies on the JDK we compute these
// offsets at run-time.
static int override_offset;
static void compute_offsets();
public:
// Accessors
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.reflect.Method objects
private:
// Note that to reduce dependencies on the JDK we compute these
// offsets at run-time.
static int clazz_offset;
static int name_offset;
static int returnType_offset;
static int parameterTypes_offset;
static int exceptionTypes_offset;
static int slot_offset;
static int modifiers_offset;
static int signature_offset;
static int annotations_offset;
static int parameter_annotations_offset;
static int annotation_default_offset;
static void compute_offsets();
public:
// Allocation
// Accessors
static bool has_signature_field();
static bool has_annotations_field();
static bool has_parameter_annotations_field();
static bool has_annotation_default_field();
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.reflect.Constructor objects
private:
// Note that to reduce dependencies on the JDK we compute these
// offsets at run-time.
static int clazz_offset;
static int parameterTypes_offset;
static int exceptionTypes_offset;
static int slot_offset;
static int modifiers_offset;
static int signature_offset;
static int annotations_offset;
static int parameter_annotations_offset;
static void compute_offsets();
public:
// Allocation
// Accessors
static bool has_signature_field();
static bool has_annotations_field();
static bool has_parameter_annotations_field();
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.reflect.Field objects
private:
// Note that to reduce dependencies on the JDK we compute these
// offsets at run-time.
static int clazz_offset;
static int name_offset;
static int type_offset;
static int slot_offset;
static int modifiers_offset;
static int signature_offset;
static int annotations_offset;
static void compute_offsets();
public:
// Allocation
// Accessors
static bool has_signature_field();
static bool has_annotations_field();
static bool has_parameter_annotations_field();
static bool has_annotation_default_field();
// Debugging
friend class JavaClasses;
};
// Interface to sun.reflect.ConstantPool objects
class sun_reflect_ConstantPool {
private:
// Note that to reduce dependencies on the JDK we compute these
// offsets at run-time.
static int _cp_oop_offset;
static void compute_offsets();
public:
// Allocation
// Accessors
static int cp_oop_offset() {
return _cp_oop_offset;
}
// Debugging
friend class JavaClasses;
};
// Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
private:
static int _base_offset;
static void compute_offsets();
public:
static int base_offset() {
return _base_offset;
}
// Debugging
friend class JavaClasses;
};
// Interface to java.lang primitive type boxing objects:
// - java.lang.Boolean
// - java.lang.Character
// - java.lang.Float
// - java.lang.Double
// - java.lang.Byte
// - java.lang.Short
// - java.lang.Integer
// - java.lang.Long
// This could be separated out into 8 individual classes.
private:
enum {
hc_value_offset = 0
};
static int value_offset;
static int long_value_offset;
public:
// Allocation. Returns a boxed value, or NULL for invalid type.
// Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
}
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.ref.Reference objects
public:
enum {
hc_referent_offset = 0,
};
enum {
};
static int referent_offset;
static int queue_offset;
static int next_offset;
static int discovered_offset;
static int static_lock_offset;
static int static_pending_offset;
static int number_of_fake_oop_fields;
// Accessors
}
}
}
}
}
}
}
}
}
}
}
}
// Accessors for statics
static oop pending_list_lock();
static oop pending_list();
static HeapWord* pending_list_addr();
};
// Interface to java.lang.ref.SoftReference objects
public:
enum {
// The timestamp is a long field and may need to be adjusted for alignment.
};
enum {
};
static int timestamp_offset;
static int static_clock_offset;
// Accessors
// Accessors for statics
};
// Interface to java.lang.invoke.MethodHandle objects
class MethodHandleEntry;
friend class JavaClasses;
private:
static void compute_offsets();
public:
// Accessors
// Testers
}
}
// Accessors for code generation:
};
// Interface to java.lang.invoke.LambdaForm objects
// (These are a private interface for managing adapter code generation.)
friend class JavaClasses;
private:
static void compute_offsets();
public:
// Accessors
// Testers
}
}
// Accessors for code generation:
};
// Interface to java.lang.invoke.MemberName objects
// (These are a private interface for Java code to query the class hierarchy.)
friend class JavaClasses;
private:
// From java.lang.invoke.MemberName:
// private Class<?> clazz; // class in which the method is defined
// private String name; // may be null if not yet materialized
// private Object type; // may be null if not yet materialized
// private int flags; // modifier bits; see reflect.Modifier
// private Object vmtarget; // VM-specific target value
// private intptr_t vmindex; // member index within class or interface
static int _clazz_offset;
static int _name_offset;
static int _type_offset;
static int _flags_offset;
static int _vmtarget_offset;
static int _vmindex_offset;
static void compute_offsets();
public:
// Accessors
// Testers
}
}
// Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
enum {
// The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
};
// Accessors for code generation:
};
// Interface to java.lang.invoke.MethodType objects
friend class JavaClasses;
private:
static int _rtype_offset;
static int _ptypes_offset;
static void compute_offsets();
public:
// Accessors
}
// Accessors for code generation:
};
// Interface to java.lang.invoke.CallSite objects
friend class JavaClasses;
private:
static int _target_offset;
static void compute_offsets();
public:
// Accessors
static void set_target_volatile(oop site, oop target) { site->obj_field_put_volatile(_target_offset, target); }
// Testers
}
}
// Accessors for code generation:
};
// Interface to java.security.AccessControlContext objects
private:
// Note that for this class the layout changed between JDK1.2 and JDK1.3,
// so we compute the offsets at startup rather than hard-wiring them.
static int _context_offset;
static int _privilegedContext_offset;
static int _isPrivileged_offset;
static int _isAuthorized_offset;
static void compute_offsets();
public:
friend class JavaClasses;
};
// Interface to java.lang.ClassLoader objects
private:
enum {
hc_parent_offset = 0
};
static bool offsets_computed;
static int parent_offset;
static int parallelCapable_offset;
static void compute_offsets();
public:
// Support for parallelCapable field
// Fix for 4474172
// Testers
}
}
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.System objects
private:
enum {
hc_static_in_offset = 0,
};
static int static_in_offset;
static int static_out_offset;
static int static_err_offset;
static int static_security_offset;
public:
static int in_offset_in_bytes();
static int out_offset_in_bytes();
static int err_offset_in_bytes();
static bool has_security_manager();
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.StackTraceElement objects
private:
enum {
};
static int declaringClass_offset;
static int methodName_offset;
static int fileName_offset;
static int lineNumber_offset;
public:
// Setters
// Create an instance of StackTraceElement
// Debugging
friend class JavaClasses;
};
// Interface to java.lang.AssertionStatusDirectives objects
private:
enum {
};
static int classes_offset;
static int classEnabled_offset;
static int packages_offset;
static int packageEnabled_offset;
static int deflt_offset;
public:
// Setters
// Debugging
friend class JavaClasses;
};
private:
static int _limit_offset;
public:
static int limit_offset();
static void compute_offsets();
};
private:
static int _owner_offset;
public:
static void initialize(TRAPS);
};
// Use to declare fields that need to be injected into Java classes
// for the JVM to use. The name_index and signature_index are
// declared in vmSymbols. The may_be_java flag is used to declare
// fields that might already exist in Java but should be injected if
// they don't. Otherwise the field is unconditionally injected and
// the JVM uses the injected one. This is to ensure that name
// collisions don't occur. In general may_be_java should be false
// unless there's a good reason.
class InjectedField {
public:
const bool may_be_java;
int compute_offset();
// Find the Symbol for this index
}
};
// Interface to hard-coded offset checking
private:
static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
public:
enum InjectedFieldID {
};
static void compute_hard_coded_offsets();
static void compute_offsets();
};
#endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP