src/share/vm/classfile/javaClasses.hpp

Wed, 18 Sep 2013 07:02:10 -0700

author
dcubed
date
Wed, 18 Sep 2013 07:02:10 -0700
changeset 5743
63147986a428
parent 5496
ca0165daa6ec
child 6413
595c0f60d50d
permissions
-rw-r--r--

8019835: Strings interned in different threads equal but does not ==
Summary: Add -XX:+VerifyStringTableAtExit option and code to verify StringTable invariants.
Reviewed-by: rdurbin, sspitsyn, coleenp

duke@435 1 /*
coleenp@4466 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP
stefank@2314 26 #define SHARE_VM_CLASSFILE_JAVACLASSES_HPP
stefank@2314 27
stefank@2314 28 #include "classfile/systemDictionary.hpp"
stefank@2314 29 #include "jvmtifiles/jvmti.h"
stefank@2314 30 #include "oops/oop.hpp"
stefank@2314 31 #include "runtime/os.hpp"
stefank@2314 32 #include "utilities/utf8.hpp"
stefank@2314 33
duke@435 34 // Interface for manipulating the basic Java classes.
duke@435 35 //
duke@435 36 // All dependencies on layout of actual Java classes should be kept here.
duke@435 37 // If the layout of any of the classes above changes the offsets must be adjusted.
duke@435 38 //
duke@435 39 // For most classes we hardwire the offsets for performance reasons. In certain
duke@435 40 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
duke@435 41 // startup since the layout here differs between JDK1.2 and JDK1.3.
duke@435 42 //
duke@435 43 // Note that fields (static and non-static) are arranged with oops before non-oops
duke@435 44 // on a per class basis. The offsets below have to reflect this ordering.
duke@435 45 //
duke@435 46 // When editing the layouts please update the check_offset verification code
duke@435 47 // correspondingly. The names in the enums must be identical to the actual field
duke@435 48 // names in order for the verification code to work.
duke@435 49
duke@435 50
duke@435 51 // Interface to java.lang.String objects
duke@435 52
duke@435 53 class java_lang_String : AllStatic {
duke@435 54 private:
duke@435 55 static int value_offset;
duke@435 56 static int offset_offset;
duke@435 57 static int count_offset;
duke@435 58 static int hash_offset;
duke@435 59
kvn@3760 60 static bool initialized;
kvn@3760 61
coleenp@4037 62 static Handle basic_create(int length, TRAPS);
duke@435 63
kvn@3760 64 static void set_value( oop string, typeArrayOop buffer) {
kvn@3760 65 assert(initialized, "Must be initialized");
kvn@3760 66 string->obj_field_put(value_offset, (oop)buffer);
kvn@3760 67 }
kvn@3760 68 static void set_offset(oop string, int offset) {
kvn@3760 69 assert(initialized, "Must be initialized");
kvn@3760 70 if (offset_offset > 0) {
kvn@3760 71 string->int_field_put(offset_offset, offset);
kvn@3760 72 }
kvn@3760 73 }
kvn@3760 74 static void set_count( oop string, int count) {
kvn@3760 75 assert(initialized, "Must be initialized");
kvn@3760 76 if (count_offset > 0) {
kvn@3760 77 string->int_field_put(count_offset, count);
kvn@3760 78 }
kvn@3760 79 }
duke@435 80
duke@435 81 public:
kvn@3760 82 static void compute_offsets();
kvn@3760 83
duke@435 84 // Instance creation
duke@435 85 static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
duke@435 86 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);
duke@435 87 static Handle create_from_str(const char* utf8_str, TRAPS);
duke@435 88 static oop create_oop_from_str(const char* utf8_str, TRAPS);
coleenp@2497 89 static Handle create_from_symbol(Symbol* symbol, TRAPS);
duke@435 90 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
duke@435 91 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
duke@435 92
kvn@3760 93 static bool has_offset_field() {
kvn@3760 94 assert(initialized, "Must be initialized");
kvn@3760 95 return (offset_offset > 0);
kvn@3760 96 }
kvn@3760 97
kvn@3760 98 static bool has_count_field() {
kvn@3760 99 assert(initialized, "Must be initialized");
kvn@3760 100 return (count_offset > 0);
kvn@3760 101 }
kvn@3760 102
kvn@3760 103 static bool has_hash_field() {
kvn@3760 104 assert(initialized, "Must be initialized");
kvn@3760 105 return (hash_offset > 0);
kvn@3760 106 }
kvn@3760 107
kvn@3760 108 static int value_offset_in_bytes() {
kvn@3760 109 assert(initialized && (value_offset > 0), "Must be initialized");
kvn@3760 110 return value_offset;
kvn@3760 111 }
kvn@3760 112 static int count_offset_in_bytes() {
kvn@3760 113 assert(initialized && (count_offset > 0), "Must be initialized");
kvn@3760 114 return count_offset;
kvn@3760 115 }
kvn@3760 116 static int offset_offset_in_bytes() {
kvn@3760 117 assert(initialized && (offset_offset > 0), "Must be initialized");
kvn@3760 118 return offset_offset;
kvn@3760 119 }
kvn@3760 120 static int hash_offset_in_bytes() {
kvn@3760 121 assert(initialized && (hash_offset > 0), "Must be initialized");
kvn@3760 122 return hash_offset;
kvn@3760 123 }
duke@435 124
duke@435 125 // Accessors
duke@435 126 static typeArrayOop value(oop java_string) {
kvn@3760 127 assert(initialized && (value_offset > 0), "Must be initialized");
duke@435 128 assert(is_instance(java_string), "must be java_string");
duke@435 129 return (typeArrayOop) java_string->obj_field(value_offset);
duke@435 130 }
duke@435 131 static int offset(oop java_string) {
kvn@3760 132 assert(initialized, "Must be initialized");
duke@435 133 assert(is_instance(java_string), "must be java_string");
kvn@3760 134 if (offset_offset > 0) {
kvn@3760 135 return java_string->int_field(offset_offset);
kvn@3760 136 } else {
kvn@3760 137 return 0;
kvn@3760 138 }
duke@435 139 }
duke@435 140 static int length(oop java_string) {
kvn@3760 141 assert(initialized, "Must be initialized");
duke@435 142 assert(is_instance(java_string), "must be java_string");
kvn@3760 143 if (count_offset > 0) {
kvn@3760 144 return java_string->int_field(count_offset);
kvn@3760 145 } else {
kvn@3760 146 return ((typeArrayOop)java_string->obj_field(value_offset))->length();
kvn@3760 147 }
duke@435 148 }
duke@435 149 static int utf8_length(oop java_string);
duke@435 150
duke@435 151 // String converters
duke@435 152 static char* as_utf8_string(oop java_string);
sla@2331 153 static char* as_utf8_string(oop java_string, char* buf, int buflen);
duke@435 154 static char* as_utf8_string(oop java_string, int start, int len);
coleenp@457 155 static char* as_platform_dependent_str(Handle java_string, TRAPS);
hseigel@4987 156 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
minqi@4267 157 // produce an ascii string with all other values quoted using \u####
minqi@4267 158 static char* as_quoted_ascii(oop java_string);
duke@435 159
never@2700 160 // Compute the hash value for a java.lang.String object which would
coleenp@3865 161 // contain the characters passed in.
never@2700 162 //
coleenp@3865 163 // As the hash value used by the String object itself, in
coleenp@3865 164 // String.hashCode(). This value is normally calculated in Java code
coleenp@3865 165 // in the String.hashCode method(), but is precomputed for String
coleenp@3865 166 // objects in the shared archive file.
coleenp@3865 167 // hash P(31) from Kernighan & Ritchie
never@2700 168 //
brutisso@4335 169 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
brutisso@4335 170 template <typename T> static unsigned int hash_code(T* s, int len) {
never@2700 171 unsigned int h = 0;
never@2700 172 while (len-- > 0) {
never@2700 173 h = 31*h + (unsigned int) *s;
never@2700 174 s++;
never@2700 175 }
never@2700 176 return h;
never@2700 177 }
brutisso@4335 178 static unsigned int hash_code(oop java_string);
coleenp@3865 179
coleenp@3865 180 // This is the string hash code used by the StringTable, which may be
brutisso@4335 181 // the same as String.hashCode or an alternate hash code.
never@2700 182 static unsigned int hash_string(oop java_string);
never@2700 183
duke@435 184 static bool equals(oop java_string, jchar* chars, int len);
dcubed@5743 185 static bool equals(oop str1, oop str2);
duke@435 186
duke@435 187 // Conversion between '.' and '/' formats
duke@435 188 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
duke@435 189 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
duke@435 190
duke@435 191 // Conversion
coleenp@2497 192 static Symbol* as_symbol(Handle java_string, TRAPS);
coleenp@2497 193 static Symbol* as_symbol_or_null(oop java_string);
duke@435 194
duke@435 195 // Testers
duke@435 196 static bool is_instance(oop obj) {
never@1577 197 return obj != NULL && obj->klass() == SystemDictionary::String_klass();
duke@435 198 }
duke@435 199
duke@435 200 // Debugging
duke@435 201 static void print(Handle java_string, outputStream* st);
duke@435 202 friend class JavaClasses;
duke@435 203 };
duke@435 204
duke@435 205
duke@435 206 // Interface to java.lang.Class objects
duke@435 207
never@3137 208 #define CLASS_INJECTED_FIELDS(macro) \
coleenp@4037 209 macro(java_lang_Class, klass, intptr_signature, false) \
coleenp@4037 210 macro(java_lang_Class, array_klass, intptr_signature, false) \
never@3137 211 macro(java_lang_Class, oop_size, int_signature, false) \
coleenp@5176 212 macro(java_lang_Class, static_oop_field_count, int_signature, false) \
coleenp@5176 213 macro(java_lang_Class, protection_domain, object_signature, false) \
coleenp@5176 214 macro(java_lang_Class, init_lock, object_signature, false) \
coleenp@5176 215 macro(java_lang_Class, signers, object_signature, false)
never@3137 216
duke@435 217 class java_lang_Class : AllStatic {
never@3137 218 friend class VMStructs;
never@3137 219
duke@435 220 private:
duke@435 221 // The fake offsets are added by the class loader when java.lang.Class is loaded
duke@435 222
never@3137 223 static int _klass_offset;
never@3137 224 static int _array_klass_offset;
duke@435 225
never@3137 226 static int _oop_size_offset;
never@3137 227 static int _static_oop_field_count_offset;
duke@435 228
coleenp@5176 229 static int _protection_domain_offset;
coleenp@5176 230 static int _init_lock_offset;
coleenp@5176 231 static int _signers_offset;
coleenp@5176 232
duke@435 233 static bool offsets_computed;
duke@435 234 static int classRedefinedCount_offset;
coleenp@4037 235 static GrowableArray<Klass*>* _fixup_mirror_list;
duke@435 236
coleenp@5176 237 static void set_init_lock(oop java_class, oop init_lock);
hseigel@5372 238 static void set_protection_domain(oop java_class, oop protection_domain);
duke@435 239 public:
never@3137 240 static void compute_offsets();
never@3137 241
duke@435 242 // Instance creation
coleenp@5176 243 static oop create_mirror(KlassHandle k, Handle protection_domain, TRAPS);
never@2658 244 static void fixup_mirror(KlassHandle k, TRAPS);
duke@435 245 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
duke@435 246 // Conversion
coleenp@4037 247 static Klass* as_Klass(oop java_class);
coleenp@4037 248 static void set_klass(oop java_class, Klass* klass);
coleenp@4037 249 static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
jrose@1145 250 static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
coleenp@4037 251 Klass* refk_oop = NULL;
jrose@1145 252 BasicType result = as_BasicType(java_class, &refk_oop);
jrose@1145 253 (*reference_klass) = KlassHandle(refk_oop);
jrose@1145 254 return result;
jrose@1145 255 }
coleenp@2497 256 static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
jrose@1100 257 static void print_signature(oop java_class, outputStream *st);
duke@435 258 // Testing
jrose@567 259 static bool is_instance(oop obj) {
never@1577 260 return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
jrose@567 261 }
duke@435 262 static bool is_primitive(oop java_class);
duke@435 263 static BasicType primitive_type(oop java_class);
duke@435 264 static oop primitive_mirror(BasicType t);
duke@435 265 // JVM_NewArray support
coleenp@4037 266 static Klass* array_klass(oop java_class);
coleenp@4037 267 static void set_array_klass(oop java_class, Klass* klass);
duke@435 268 // compiler support for class operations
never@3137 269 static int klass_offset_in_bytes() { return _klass_offset; }
never@3137 270 static int array_klass_offset_in_bytes() { return _array_klass_offset; }
duke@435 271 // Support for classRedefinedCount field
duke@435 272 static int classRedefinedCount(oop the_class_mirror);
duke@435 273 static void set_classRedefinedCount(oop the_class_mirror, int value);
never@2658 274
coleenp@5176 275 // Support for embedded per-class oops
coleenp@5176 276 static oop protection_domain(oop java_class);
coleenp@5176 277 static oop init_lock(oop java_class);
coleenp@5176 278 static objArrayOop signers(oop java_class);
coleenp@5176 279 static void set_signers(oop java_class, objArrayOop signers);
coleenp@5176 280
never@2658 281 static int oop_size(oop java_class);
never@2658 282 static void set_oop_size(oop java_class, int size);
never@2658 283 static int static_oop_field_count(oop java_class);
never@2658 284 static void set_static_oop_field_count(oop java_class, int size);
never@2658 285
coleenp@4037 286 static GrowableArray<Klass*>* fixup_mirror_list() {
coleenp@4037 287 return _fixup_mirror_list;
coleenp@4037 288 }
coleenp@4037 289 static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
coleenp@4037 290 _fixup_mirror_list = v;
coleenp@4037 291 }
duke@435 292 // Debugging
duke@435 293 friend class JavaClasses;
coleenp@4037 294 friend class InstanceKlass; // verification code accesses offsets
duke@435 295 friend class ClassFileParser; // access to number_of_fake_fields
duke@435 296 };
duke@435 297
duke@435 298 // Interface to java.lang.Thread objects
duke@435 299
duke@435 300 class java_lang_Thread : AllStatic {
duke@435 301 private:
duke@435 302 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
duke@435 303 // so we compute the offsets at startup rather than hard-wiring them.
duke@435 304 static int _name_offset;
duke@435 305 static int _group_offset;
duke@435 306 static int _contextClassLoader_offset;
duke@435 307 static int _inheritedAccessControlContext_offset;
duke@435 308 static int _priority_offset;
duke@435 309 static int _eetop_offset;
duke@435 310 static int _daemon_offset;
duke@435 311 static int _stillborn_offset;
duke@435 312 static int _stackSize_offset;
duke@435 313 static int _tid_offset;
duke@435 314 static int _thread_status_offset;
duke@435 315 static int _park_blocker_offset;
duke@435 316 static int _park_event_offset ;
duke@435 317
duke@435 318 static void compute_offsets();
duke@435 319
duke@435 320 public:
duke@435 321 // Instance creation
duke@435 322 static oop create();
duke@435 323 // Returns the JavaThread associated with the thread obj
duke@435 324 static JavaThread* thread(oop java_thread);
duke@435 325 // Set JavaThread for instance
duke@435 326 static void set_thread(oop java_thread, JavaThread* thread);
duke@435 327 // Name
duke@435 328 static typeArrayOop name(oop java_thread);
duke@435 329 static void set_name(oop java_thread, typeArrayOop name);
duke@435 330 // Priority
duke@435 331 static ThreadPriority priority(oop java_thread);
duke@435 332 static void set_priority(oop java_thread, ThreadPriority priority);
duke@435 333 // Thread group
duke@435 334 static oop threadGroup(oop java_thread);
duke@435 335 // Stillborn
duke@435 336 static bool is_stillborn(oop java_thread);
duke@435 337 static void set_stillborn(oop java_thread);
duke@435 338 // Alive (NOTE: this is not really a field, but provides the correct
duke@435 339 // definition without doing a Java call)
duke@435 340 static bool is_alive(oop java_thread);
duke@435 341 // Daemon
duke@435 342 static bool is_daemon(oop java_thread);
duke@435 343 static void set_daemon(oop java_thread);
duke@435 344 // Context ClassLoader
duke@435 345 static oop context_class_loader(oop java_thread);
duke@435 346 // Control context
duke@435 347 static oop inherited_access_control_context(oop java_thread);
duke@435 348 // Stack size hint
duke@435 349 static jlong stackSize(oop java_thread);
duke@435 350 // Thread ID
duke@435 351 static jlong thread_id(oop java_thread);
duke@435 352
duke@435 353 // Blocker object responsible for thread parking
duke@435 354 static oop park_blocker(oop java_thread);
duke@435 355
duke@435 356 // Pointer to type-stable park handler, encoded as jlong.
duke@435 357 // Should be set when apparently null
duke@435 358 // For details, see unsafe.cpp Unsafe_Unpark
duke@435 359 static jlong park_event(oop java_thread);
duke@435 360 static bool set_park_event(oop java_thread, jlong ptr);
duke@435 361
duke@435 362 // Java Thread Status for JVMTI and M&M use.
duke@435 363 // This thread status info is saved in threadStatus field of
duke@435 364 // java.lang.Thread java class.
duke@435 365 enum ThreadStatus {
duke@435 366 NEW = 0,
duke@435 367 RUNNABLE = JVMTI_THREAD_STATE_ALIVE + // runnable / running
duke@435 368 JVMTI_THREAD_STATE_RUNNABLE,
duke@435 369 SLEEPING = JVMTI_THREAD_STATE_ALIVE + // Thread.sleep()
duke@435 370 JVMTI_THREAD_STATE_WAITING +
duke@435 371 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
duke@435 372 JVMTI_THREAD_STATE_SLEEPING,
duke@435 373 IN_OBJECT_WAIT = JVMTI_THREAD_STATE_ALIVE + // Object.wait()
duke@435 374 JVMTI_THREAD_STATE_WAITING +
duke@435 375 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
duke@435 376 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
duke@435 377 IN_OBJECT_WAIT_TIMED = JVMTI_THREAD_STATE_ALIVE + // Object.wait(long)
duke@435 378 JVMTI_THREAD_STATE_WAITING +
duke@435 379 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
duke@435 380 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
duke@435 381 PARKED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park()
duke@435 382 JVMTI_THREAD_STATE_WAITING +
duke@435 383 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
duke@435 384 JVMTI_THREAD_STATE_PARKED,
duke@435 385 PARKED_TIMED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park(long)
duke@435 386 JVMTI_THREAD_STATE_WAITING +
duke@435 387 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
duke@435 388 JVMTI_THREAD_STATE_PARKED,
duke@435 389 BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE + // (re-)entering a synchronization block
duke@435 390 JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
duke@435 391 TERMINATED = JVMTI_THREAD_STATE_TERMINATED
duke@435 392 };
duke@435 393 // Write thread status info to threadStatus field of java.lang.Thread.
duke@435 394 static void set_thread_status(oop java_thread_oop, ThreadStatus status);
duke@435 395 // Read thread status info from threadStatus field of java.lang.Thread.
duke@435 396 static ThreadStatus get_thread_status(oop java_thread_oop);
duke@435 397
duke@435 398 static const char* thread_status_name(oop java_thread_oop);
duke@435 399
duke@435 400 // Debugging
duke@435 401 friend class JavaClasses;
duke@435 402 };
duke@435 403
duke@435 404 // Interface to java.lang.ThreadGroup objects
duke@435 405
duke@435 406 class java_lang_ThreadGroup : AllStatic {
duke@435 407 private:
duke@435 408 static int _parent_offset;
duke@435 409 static int _name_offset;
duke@435 410 static int _threads_offset;
duke@435 411 static int _groups_offset;
duke@435 412 static int _maxPriority_offset;
duke@435 413 static int _destroyed_offset;
duke@435 414 static int _daemon_offset;
duke@435 415 static int _vmAllowSuspension_offset;
duke@435 416 static int _nthreads_offset;
duke@435 417 static int _ngroups_offset;
duke@435 418
duke@435 419 static void compute_offsets();
duke@435 420
duke@435 421 public:
duke@435 422 // parent ThreadGroup
duke@435 423 static oop parent(oop java_thread_group);
duke@435 424 // name
duke@435 425 static typeArrayOop name(oop java_thread_group);
duke@435 426 // ("name as oop" accessor is not necessary)
duke@435 427 // Number of threads in group
duke@435 428 static int nthreads(oop java_thread_group);
duke@435 429 // threads
duke@435 430 static objArrayOop threads(oop java_thread_group);
duke@435 431 // Number of threads in group
duke@435 432 static int ngroups(oop java_thread_group);
duke@435 433 // groups
duke@435 434 static objArrayOop groups(oop java_thread_group);
duke@435 435 // maxPriority in group
duke@435 436 static ThreadPriority maxPriority(oop java_thread_group);
duke@435 437 // Destroyed
duke@435 438 static bool is_destroyed(oop java_thread_group);
duke@435 439 // Daemon
duke@435 440 static bool is_daemon(oop java_thread_group);
duke@435 441 // vmAllowSuspension
duke@435 442 static bool is_vmAllowSuspension(oop java_thread_group);
duke@435 443 // Debugging
duke@435 444 friend class JavaClasses;
duke@435 445 };
duke@435 446
duke@435 447
duke@435 448
duke@435 449 // Interface to java.lang.Throwable objects
duke@435 450
duke@435 451 class java_lang_Throwable: AllStatic {
duke@435 452 friend class BacktraceBuilder;
duke@435 453
duke@435 454 private:
duke@435 455 // Offsets
duke@435 456 enum {
duke@435 457 hc_backtrace_offset = 0,
duke@435 458 hc_detailMessage_offset = 1,
duke@435 459 hc_cause_offset = 2, // New since 1.4
duke@435 460 hc_stackTrace_offset = 3 // New since 1.4
duke@435 461 };
dholmes@3018 462 enum {
dholmes@3018 463 hc_static_unassigned_stacktrace_offset = 0 // New since 1.7
dholmes@3018 464 };
duke@435 465 // Trace constants
duke@435 466 enum {
duke@435 467 trace_methods_offset = 0,
duke@435 468 trace_bcis_offset = 1,
coleenp@4037 469 trace_mirrors_offset = 2,
coleenp@4037 470 trace_next_offset = 3,
coleenp@4037 471 trace_size = 4,
duke@435 472 trace_chunk_size = 32
duke@435 473 };
duke@435 474
duke@435 475 static int backtrace_offset;
duke@435 476 static int detailMessage_offset;
duke@435 477 static int cause_offset;
duke@435 478 static int stackTrace_offset;
dholmes@3018 479 static int static_unassigned_stacktrace_offset;
duke@435 480
duke@435 481 // Printing
coleenp@4466 482 static char* print_stack_element_to_buffer(Handle mirror, int method, int version, int bci);
duke@435 483 // StackTrace (programmatic access, new since 1.4)
duke@435 484 static void clear_stacktrace(oop throwable);
duke@435 485 // No stack trace available
duke@435 486 static const char* no_stack_trace_message();
dholmes@3018 487 // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
dholmes@3018 488 static void set_stacktrace(oop throwable, oop st_element_array);
dholmes@3018 489 static oop unassigned_stacktrace();
duke@435 490
duke@435 491 public:
duke@435 492 // Backtrace
duke@435 493 static oop backtrace(oop throwable);
duke@435 494 static void set_backtrace(oop throwable, oop value);
duke@435 495 // Needed by JVMTI to filter out this internal field.
duke@435 496 static int get_backtrace_offset() { return backtrace_offset;}
duke@435 497 static int get_detailMessage_offset() { return detailMessage_offset;}
duke@435 498 // Message
duke@435 499 static oop message(oop throwable);
duke@435 500 static oop message(Handle throwable);
duke@435 501 static void set_message(oop throwable, oop value);
coleenp@4466 502 static void print_stack_element(outputStream *st, Handle mirror, int method,
coleenp@4466 503 int version, int bci);
coleenp@4466 504 static void print_stack_element(outputStream *st, methodHandle method, int bci);
duke@435 505 static void print_stack_usage(Handle stream);
duke@435 506
duke@435 507 // Allocate space for backtrace (created but stack trace not filled in)
duke@435 508 static void allocate_backtrace(Handle throwable, TRAPS);
duke@435 509 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
duke@435 510 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
duke@435 511 // Fill in current stack trace, can cause GC
coleenp@2804 512 static void fill_in_stack_trace(Handle throwable, methodHandle method, TRAPS);
coleenp@2804 513 static void fill_in_stack_trace(Handle throwable, methodHandle method = methodHandle());
duke@435 514 // Programmatic access to stack trace
duke@435 515 static oop get_stack_trace_element(oop throwable, int index, TRAPS);
duke@435 516 static int get_stack_trace_depth(oop throwable, TRAPS);
duke@435 517 // Printing
duke@435 518 static void print(oop throwable, outputStream* st);
duke@435 519 static void print(Handle throwable, outputStream* st);
duke@435 520 static void print_stack_trace(oop throwable, outputStream* st);
duke@435 521 // Debugging
duke@435 522 friend class JavaClasses;
duke@435 523 };
duke@435 524
duke@435 525
duke@435 526 // Interface to java.lang.reflect.AccessibleObject objects
duke@435 527
duke@435 528 class java_lang_reflect_AccessibleObject: AllStatic {
duke@435 529 private:
duke@435 530 // Note that to reduce dependencies on the JDK we compute these
duke@435 531 // offsets at run-time.
duke@435 532 static int override_offset;
duke@435 533
duke@435 534 static void compute_offsets();
duke@435 535
duke@435 536 public:
duke@435 537 // Accessors
duke@435 538 static jboolean override(oop reflect);
duke@435 539 static void set_override(oop reflect, jboolean value);
duke@435 540
duke@435 541 // Debugging
duke@435 542 friend class JavaClasses;
duke@435 543 };
duke@435 544
duke@435 545
duke@435 546 // Interface to java.lang.reflect.Method objects
duke@435 547
duke@435 548 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
duke@435 549 private:
duke@435 550 // Note that to reduce dependencies on the JDK we compute these
duke@435 551 // offsets at run-time.
duke@435 552 static int clazz_offset;
duke@435 553 static int name_offset;
duke@435 554 static int returnType_offset;
duke@435 555 static int parameterTypes_offset;
duke@435 556 static int exceptionTypes_offset;
duke@435 557 static int slot_offset;
duke@435 558 static int modifiers_offset;
duke@435 559 static int signature_offset;
duke@435 560 static int annotations_offset;
duke@435 561 static int parameter_annotations_offset;
duke@435 562 static int annotation_default_offset;
stefank@4393 563 static int type_annotations_offset;
duke@435 564
duke@435 565 static void compute_offsets();
duke@435 566
duke@435 567 public:
duke@435 568 // Allocation
duke@435 569 static Handle create(TRAPS);
duke@435 570
duke@435 571 // Accessors
duke@435 572 static oop clazz(oop reflect);
duke@435 573 static void set_clazz(oop reflect, oop value);
duke@435 574
duke@435 575 static oop name(oop method);
duke@435 576 static void set_name(oop method, oop value);
duke@435 577
duke@435 578 static oop return_type(oop method);
duke@435 579 static void set_return_type(oop method, oop value);
duke@435 580
duke@435 581 static oop parameter_types(oop method);
duke@435 582 static void set_parameter_types(oop method, oop value);
duke@435 583
duke@435 584 static oop exception_types(oop method);
duke@435 585 static void set_exception_types(oop method, oop value);
duke@435 586
duke@435 587 static int slot(oop reflect);
duke@435 588 static void set_slot(oop reflect, int value);
duke@435 589
duke@435 590 static int modifiers(oop method);
duke@435 591 static void set_modifiers(oop method, int value);
duke@435 592
duke@435 593 static bool has_signature_field();
duke@435 594 static oop signature(oop method);
duke@435 595 static void set_signature(oop method, oop value);
duke@435 596
duke@435 597 static bool has_annotations_field();
duke@435 598 static oop annotations(oop method);
duke@435 599 static void set_annotations(oop method, oop value);
duke@435 600
duke@435 601 static bool has_parameter_annotations_field();
duke@435 602 static oop parameter_annotations(oop method);
duke@435 603 static void set_parameter_annotations(oop method, oop value);
duke@435 604
duke@435 605 static bool has_annotation_default_field();
duke@435 606 static oop annotation_default(oop method);
duke@435 607 static void set_annotation_default(oop method, oop value);
duke@435 608
stefank@4393 609 static bool has_type_annotations_field();
stefank@4393 610 static oop type_annotations(oop method);
stefank@4393 611 static void set_type_annotations(oop method, oop value);
stefank@4393 612
duke@435 613 // Debugging
duke@435 614 friend class JavaClasses;
duke@435 615 };
duke@435 616
duke@435 617
duke@435 618 // Interface to java.lang.reflect.Constructor objects
duke@435 619
duke@435 620 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
duke@435 621 private:
duke@435 622 // Note that to reduce dependencies on the JDK we compute these
duke@435 623 // offsets at run-time.
duke@435 624 static int clazz_offset;
duke@435 625 static int parameterTypes_offset;
duke@435 626 static int exceptionTypes_offset;
duke@435 627 static int slot_offset;
duke@435 628 static int modifiers_offset;
duke@435 629 static int signature_offset;
duke@435 630 static int annotations_offset;
duke@435 631 static int parameter_annotations_offset;
stefank@4393 632 static int type_annotations_offset;
duke@435 633
duke@435 634 static void compute_offsets();
duke@435 635
duke@435 636 public:
duke@435 637 // Allocation
duke@435 638 static Handle create(TRAPS);
duke@435 639
duke@435 640 // Accessors
duke@435 641 static oop clazz(oop reflect);
duke@435 642 static void set_clazz(oop reflect, oop value);
duke@435 643
duke@435 644 static oop parameter_types(oop constructor);
duke@435 645 static void set_parameter_types(oop constructor, oop value);
duke@435 646
duke@435 647 static oop exception_types(oop constructor);
duke@435 648 static void set_exception_types(oop constructor, oop value);
duke@435 649
duke@435 650 static int slot(oop reflect);
duke@435 651 static void set_slot(oop reflect, int value);
duke@435 652
duke@435 653 static int modifiers(oop constructor);
duke@435 654 static void set_modifiers(oop constructor, int value);
duke@435 655
duke@435 656 static bool has_signature_field();
duke@435 657 static oop signature(oop constructor);
duke@435 658 static void set_signature(oop constructor, oop value);
duke@435 659
duke@435 660 static bool has_annotations_field();
duke@435 661 static oop annotations(oop constructor);
duke@435 662 static void set_annotations(oop constructor, oop value);
duke@435 663
duke@435 664 static bool has_parameter_annotations_field();
duke@435 665 static oop parameter_annotations(oop method);
duke@435 666 static void set_parameter_annotations(oop method, oop value);
duke@435 667
stefank@4393 668 static bool has_type_annotations_field();
stefank@4393 669 static oop type_annotations(oop constructor);
stefank@4393 670 static void set_type_annotations(oop constructor, oop value);
stefank@4393 671
duke@435 672 // Debugging
duke@435 673 friend class JavaClasses;
duke@435 674 };
duke@435 675
duke@435 676
duke@435 677 // Interface to java.lang.reflect.Field objects
duke@435 678
duke@435 679 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
duke@435 680 private:
duke@435 681 // Note that to reduce dependencies on the JDK we compute these
duke@435 682 // offsets at run-time.
duke@435 683 static int clazz_offset;
duke@435 684 static int name_offset;
duke@435 685 static int type_offset;
duke@435 686 static int slot_offset;
duke@435 687 static int modifiers_offset;
duke@435 688 static int signature_offset;
duke@435 689 static int annotations_offset;
stefank@4393 690 static int type_annotations_offset;
duke@435 691
duke@435 692 static void compute_offsets();
duke@435 693
duke@435 694 public:
duke@435 695 // Allocation
duke@435 696 static Handle create(TRAPS);
duke@435 697
duke@435 698 // Accessors
duke@435 699 static oop clazz(oop reflect);
duke@435 700 static void set_clazz(oop reflect, oop value);
duke@435 701
duke@435 702 static oop name(oop field);
duke@435 703 static void set_name(oop field, oop value);
duke@435 704
duke@435 705 static oop type(oop field);
duke@435 706 static void set_type(oop field, oop value);
duke@435 707
duke@435 708 static int slot(oop reflect);
duke@435 709 static void set_slot(oop reflect, int value);
duke@435 710
duke@435 711 static int modifiers(oop field);
duke@435 712 static void set_modifiers(oop field, int value);
duke@435 713
duke@435 714 static bool has_signature_field();
duke@435 715 static oop signature(oop constructor);
duke@435 716 static void set_signature(oop constructor, oop value);
duke@435 717
duke@435 718 static bool has_annotations_field();
duke@435 719 static oop annotations(oop constructor);
duke@435 720 static void set_annotations(oop constructor, oop value);
duke@435 721
duke@435 722 static bool has_parameter_annotations_field();
duke@435 723 static oop parameter_annotations(oop method);
duke@435 724 static void set_parameter_annotations(oop method, oop value);
duke@435 725
duke@435 726 static bool has_annotation_default_field();
duke@435 727 static oop annotation_default(oop method);
duke@435 728 static void set_annotation_default(oop method, oop value);
duke@435 729
stefank@4393 730 static bool has_type_annotations_field();
stefank@4393 731 static oop type_annotations(oop field);
stefank@4393 732 static void set_type_annotations(oop field, oop value);
stefank@4393 733
duke@435 734 // Debugging
duke@435 735 friend class JavaClasses;
duke@435 736 };
duke@435 737
coleenp@4398 738 class java_lang_reflect_Parameter {
coleenp@4398 739 private:
coleenp@4398 740 // Note that to reduce dependencies on the JDK we compute these
coleenp@4398 741 // offsets at run-time.
coleenp@4398 742 static int name_offset;
coleenp@4398 743 static int modifiers_offset;
coleenp@4398 744 static int index_offset;
coleenp@4398 745 static int executable_offset;
coleenp@4398 746
coleenp@4398 747 static void compute_offsets();
coleenp@4398 748
coleenp@4398 749 public:
coleenp@4398 750 // Allocation
coleenp@4398 751 static Handle create(TRAPS);
coleenp@4398 752
coleenp@4398 753 // Accessors
coleenp@4398 754 static oop name(oop field);
coleenp@4398 755 static void set_name(oop field, oop value);
coleenp@4398 756
coleenp@4398 757 static int index(oop reflect);
coleenp@4398 758 static void set_index(oop reflect, int value);
coleenp@4398 759
coleenp@4398 760 static int modifiers(oop reflect);
coleenp@4398 761 static void set_modifiers(oop reflect, int value);
coleenp@4398 762
coleenp@4398 763 static oop executable(oop constructor);
coleenp@4398 764 static void set_executable(oop constructor, oop value);
coleenp@4398 765
coleenp@4398 766 friend class JavaClasses;
coleenp@4398 767 };
coleenp@4398 768
duke@435 769 // Interface to sun.reflect.ConstantPool objects
duke@435 770 class sun_reflect_ConstantPool {
duke@435 771 private:
duke@435 772 // Note that to reduce dependencies on the JDK we compute these
duke@435 773 // offsets at run-time.
coleenp@4037 774 static int _oop_offset;
duke@435 775
duke@435 776 static void compute_offsets();
duke@435 777
duke@435 778 public:
duke@435 779 // Allocation
duke@435 780 static Handle create(TRAPS);
duke@435 781
duke@435 782 // Accessors
coleenp@4037 783 static void set_cp(oop reflect, ConstantPool* value);
coleenp@4037 784 static int oop_offset() {
coleenp@4037 785 return _oop_offset;
duke@435 786 }
duke@435 787
coleenp@4037 788 static ConstantPool* get_cp(oop reflect);
coleenp@4037 789
duke@435 790 // Debugging
duke@435 791 friend class JavaClasses;
duke@435 792 };
duke@435 793
duke@435 794 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
duke@435 795 class sun_reflect_UnsafeStaticFieldAccessorImpl {
duke@435 796 private:
duke@435 797 static int _base_offset;
duke@435 798 static void compute_offsets();
duke@435 799
duke@435 800 public:
duke@435 801 static int base_offset() {
duke@435 802 return _base_offset;
duke@435 803 }
duke@435 804
duke@435 805 // Debugging
duke@435 806 friend class JavaClasses;
duke@435 807 };
duke@435 808
duke@435 809 // Interface to java.lang primitive type boxing objects:
duke@435 810 // - java.lang.Boolean
duke@435 811 // - java.lang.Character
duke@435 812 // - java.lang.Float
duke@435 813 // - java.lang.Double
duke@435 814 // - java.lang.Byte
duke@435 815 // - java.lang.Short
duke@435 816 // - java.lang.Integer
duke@435 817 // - java.lang.Long
duke@435 818
duke@435 819 // This could be separated out into 8 individual classes.
duke@435 820
duke@435 821 class java_lang_boxing_object: AllStatic {
duke@435 822 private:
duke@435 823 enum {
duke@435 824 hc_value_offset = 0
duke@435 825 };
duke@435 826 static int value_offset;
kvn@600 827 static int long_value_offset;
duke@435 828
jrose@567 829 static oop initialize_and_allocate(BasicType type, TRAPS);
duke@435 830 public:
duke@435 831 // Allocation. Returns a boxed value, or NULL for invalid type.
duke@435 832 static oop create(BasicType type, jvalue* value, TRAPS);
duke@435 833 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
duke@435 834 static BasicType get_value(oop box, jvalue* value);
duke@435 835 static BasicType set_value(oop box, jvalue* value);
jrose@567 836 static BasicType basic_type(oop box);
jrose@567 837 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
jrose@567 838 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
jrose@1100 839 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
jrose@1100 840 static void print(BasicType type, jvalue* value, outputStream* st);
duke@435 841
kvn@600 842 static int value_offset_in_bytes(BasicType type) {
kvn@600 843 return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
kvn@600 844 value_offset;
kvn@600 845 }
duke@435 846
duke@435 847 // Debugging
duke@435 848 friend class JavaClasses;
duke@435 849 };
duke@435 850
duke@435 851
duke@435 852
duke@435 853 // Interface to java.lang.ref.Reference objects
duke@435 854
duke@435 855 class java_lang_ref_Reference: AllStatic {
duke@435 856 public:
duke@435 857 enum {
duke@435 858 hc_referent_offset = 0,
duke@435 859 hc_queue_offset = 1,
duke@435 860 hc_next_offset = 2,
duke@435 861 hc_discovered_offset = 3 // Is not last, see SoftRefs.
duke@435 862 };
duke@435 863 enum {
duke@435 864 hc_static_lock_offset = 0,
duke@435 865 hc_static_pending_offset = 1
duke@435 866 };
duke@435 867
duke@435 868 static int referent_offset;
duke@435 869 static int queue_offset;
duke@435 870 static int next_offset;
duke@435 871 static int discovered_offset;
duke@435 872 static int static_lock_offset;
duke@435 873 static int static_pending_offset;
duke@435 874 static int number_of_fake_oop_fields;
duke@435 875
duke@435 876 // Accessors
coleenp@548 877 static oop referent(oop ref) {
coleenp@548 878 return ref->obj_field(referent_offset);
coleenp@548 879 }
coleenp@548 880 static void set_referent(oop ref, oop value) {
coleenp@548 881 ref->obj_field_put(referent_offset, value);
coleenp@548 882 }
coleenp@548 883 static void set_referent_raw(oop ref, oop value) {
twisti@3131 884 ref->obj_field_put_raw(referent_offset, value);
coleenp@548 885 }
coleenp@548 886 static HeapWord* referent_addr(oop ref) {
coleenp@548 887 return ref->obj_field_addr<HeapWord>(referent_offset);
coleenp@548 888 }
coleenp@548 889 static oop next(oop ref) {
coleenp@548 890 return ref->obj_field(next_offset);
coleenp@548 891 }
coleenp@548 892 static void set_next(oop ref, oop value) {
coleenp@548 893 ref->obj_field_put(next_offset, value);
coleenp@548 894 }
coleenp@548 895 static void set_next_raw(oop ref, oop value) {
twisti@3131 896 ref->obj_field_put_raw(next_offset, value);
coleenp@548 897 }
coleenp@548 898 static HeapWord* next_addr(oop ref) {
coleenp@548 899 return ref->obj_field_addr<HeapWord>(next_offset);
coleenp@548 900 }
coleenp@548 901 static oop discovered(oop ref) {
coleenp@548 902 return ref->obj_field(discovered_offset);
coleenp@548 903 }
coleenp@548 904 static void set_discovered(oop ref, oop value) {
coleenp@548 905 ref->obj_field_put(discovered_offset, value);
coleenp@548 906 }
coleenp@548 907 static void set_discovered_raw(oop ref, oop value) {
twisti@3131 908 ref->obj_field_put_raw(discovered_offset, value);
coleenp@548 909 }
coleenp@548 910 static HeapWord* discovered_addr(oop ref) {
coleenp@548 911 return ref->obj_field_addr<HeapWord>(discovered_offset);
coleenp@548 912 }
coleenp@548 913 // Accessors for statics
coleenp@548 914 static oop pending_list_lock();
coleenp@548 915 static oop pending_list();
duke@435 916
coleenp@4037 917 static HeapWord* pending_list_lock_addr();
coleenp@548 918 static HeapWord* pending_list_addr();
duke@435 919 };
duke@435 920
duke@435 921
duke@435 922 // Interface to java.lang.ref.SoftReference objects
duke@435 923
duke@435 924 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
duke@435 925 public:
duke@435 926 enum {
duke@435 927 // The timestamp is a long field and may need to be adjusted for alignment.
kvn@600 928 hc_timestamp_offset = hc_discovered_offset + 1
duke@435 929 };
duke@435 930 enum {
duke@435 931 hc_static_clock_offset = 0
duke@435 932 };
duke@435 933
duke@435 934 static int timestamp_offset;
duke@435 935 static int static_clock_offset;
duke@435 936
duke@435 937 // Accessors
duke@435 938 static jlong timestamp(oop ref);
duke@435 939
duke@435 940 // Accessors for statics
duke@435 941 static jlong clock();
duke@435 942 static void set_clock(jlong value);
duke@435 943 };
duke@435 944
duke@435 945
jrose@2639 946 // Interface to java.lang.invoke.MethodHandle objects
jrose@1145 947
jrose@1145 948 class MethodHandleEntry;
jrose@1145 949
jrose@2639 950 class java_lang_invoke_MethodHandle: AllStatic {
jrose@1145 951 friend class JavaClasses;
jrose@1145 952
jrose@1145 953 private:
twisti@3969 954 static int _type_offset; // the MethodType of this MH
twisti@3969 955 static int _form_offset; // the LambdaForm of this MH
jrose@1145 956
jrose@1145 957 static void compute_offsets();
jrose@1145 958
jrose@1145 959 public:
jrose@1145 960 // Accessors
jrose@1145 961 static oop type(oop mh);
jrose@1145 962 static void set_type(oop mh, oop mtype);
jrose@1145 963
twisti@3969 964 static oop form(oop mh);
twisti@3969 965 static void set_form(oop mh, oop lform);
jrose@1145 966
jrose@1145 967 // Testers
coleenp@4037 968 static bool is_subclass(Klass* klass) {
hseigel@4278 969 return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
jrose@1145 970 }
jrose@1145 971 static bool is_instance(oop obj) {
jrose@1145 972 return obj != NULL && is_subclass(obj->klass());
jrose@1145 973 }
jrose@1145 974
jrose@1145 975 // Accessors for code generation:
jrose@1145 976 static int type_offset_in_bytes() { return _type_offset; }
twisti@3969 977 static int form_offset_in_bytes() { return _form_offset; }
jrose@1145 978 };
jrose@1145 979
sspitsyn@5496 980 // Interface to java.lang.invoke.DirectMethodHandle objects
sspitsyn@5496 981
sspitsyn@5496 982 class java_lang_invoke_DirectMethodHandle: AllStatic {
sspitsyn@5496 983 friend class JavaClasses;
sspitsyn@5496 984
sspitsyn@5496 985 private:
sspitsyn@5496 986 static int _member_offset; // the MemberName of this DMH
sspitsyn@5496 987
sspitsyn@5496 988 static void compute_offsets();
sspitsyn@5496 989
sspitsyn@5496 990 public:
sspitsyn@5496 991 // Accessors
sspitsyn@5496 992 static oop member(oop mh);
sspitsyn@5496 993
sspitsyn@5496 994 // Testers
sspitsyn@5496 995 static bool is_subclass(Klass* klass) {
sspitsyn@5496 996 return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
sspitsyn@5496 997 }
sspitsyn@5496 998 static bool is_instance(oop obj) {
sspitsyn@5496 999 return obj != NULL && is_subclass(obj->klass());
sspitsyn@5496 1000 }
sspitsyn@5496 1001
sspitsyn@5496 1002 // Accessors for code generation:
sspitsyn@5496 1003 static int member_offset_in_bytes() { return _member_offset; }
sspitsyn@5496 1004 };
sspitsyn@5496 1005
twisti@3969 1006 // Interface to java.lang.invoke.LambdaForm objects
twisti@3969 1007 // (These are a private interface for managing adapter code generation.)
never@3137 1008
twisti@3969 1009 class java_lang_invoke_LambdaForm: AllStatic {
jrose@1145 1010 friend class JavaClasses;
jrose@1145 1011
jrose@1145 1012 private:
twisti@3969 1013 static int _vmentry_offset; // type is MemberName
twisti@3969 1014
jrose@1145 1015 static void compute_offsets();
jrose@1145 1016
jrose@1145 1017 public:
jrose@1145 1018 // Accessors
twisti@3969 1019 static oop vmentry(oop lform);
twisti@3969 1020 static void set_vmentry(oop lform, oop invoker);
jrose@1145 1021
jrose@1145 1022 // Testers
coleenp@4037 1023 static bool is_subclass(Klass* klass) {
twisti@3969 1024 return SystemDictionary::LambdaForm_klass() != NULL &&
hseigel@4278 1025 klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
jrose@1145 1026 }
jrose@1145 1027 static bool is_instance(oop obj) {
jrose@1145 1028 return obj != NULL && is_subclass(obj->klass());
jrose@1145 1029 }
jrose@1145 1030
jrose@1145 1031 // Accessors for code generation:
twisti@3969 1032 static int vmentry_offset_in_bytes() { return _vmentry_offset; }
jrose@1145 1033 };
jrose@1145 1034
never@3105 1035
jrose@2639 1036 // Interface to java.lang.invoke.MemberName objects
jrose@1145 1037 // (These are a private interface for Java code to query the class hierarchy.)
jrose@1145 1038
twisti@3969 1039 #define MEMBERNAME_INJECTED_FIELDS(macro) \
coleenp@4037 1040 macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
twisti@3969 1041 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false) \
coleenp@4037 1042 macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
never@3137 1043
jrose@2639 1044 class java_lang_invoke_MemberName: AllStatic {
jrose@1145 1045 friend class JavaClasses;
jrose@1145 1046
jrose@1145 1047 private:
jrose@2639 1048 // From java.lang.invoke.MemberName:
jrose@1145 1049 // private Class<?> clazz; // class in which the method is defined
jrose@1145 1050 // private String name; // may be null if not yet materialized
jrose@1145 1051 // private Object type; // may be null if not yet materialized
jrose@1145 1052 // private int flags; // modifier bits; see reflect.Modifier
coleenp@4037 1053 // private intptr vmtarget; // VM-specific target value
twisti@3969 1054 // private intptr_t vmindex; // member index within class or interface
jrose@1145 1055 static int _clazz_offset;
jrose@1145 1056 static int _name_offset;
jrose@1145 1057 static int _type_offset;
jrose@1145 1058 static int _flags_offset;
jrose@1145 1059 static int _vmtarget_offset;
coleenp@4037 1060 static int _vmloader_offset;
jrose@1145 1061 static int _vmindex_offset;
jrose@1145 1062
jrose@1145 1063 static void compute_offsets();
jrose@1145 1064
jrose@1145 1065 public:
jrose@1145 1066 // Accessors
jrose@1145 1067 static oop clazz(oop mname);
jrose@1145 1068 static void set_clazz(oop mname, oop clazz);
jrose@1145 1069
jrose@1145 1070 static oop type(oop mname);
jrose@1145 1071 static void set_type(oop mname, oop type);
jrose@1145 1072
jrose@1145 1073 static oop name(oop mname);
jrose@1145 1074 static void set_name(oop mname, oop name);
jrose@1145 1075
jrose@1145 1076 static int flags(oop mname);
jrose@1145 1077 static void set_flags(oop mname, int flags);
jrose@1145 1078
coleenp@4037 1079 static Metadata* vmtarget(oop mname);
coleenp@4037 1080 static void set_vmtarget(oop mname, Metadata* target);
sspitsyn@4965 1081 #if INCLUDE_JVMTI
sspitsyn@4965 1082 static void adjust_vmtarget(oop mname, Metadata* target);
sspitsyn@4965 1083 #endif // INCLUDE_JVMTI
jrose@1145 1084
twisti@3969 1085 static intptr_t vmindex(oop mname);
twisti@3969 1086 static void set_vmindex(oop mname, intptr_t index);
jrose@1145 1087
jrose@1145 1088 // Testers
coleenp@4037 1089 static bool is_subclass(Klass* klass) {
hseigel@4278 1090 return klass->is_subclass_of(SystemDictionary::MemberName_klass());
jrose@1145 1091 }
jrose@1145 1092 static bool is_instance(oop obj) {
jrose@1145 1093 return obj != NULL && is_subclass(obj->klass());
jrose@1145 1094 }
jrose@1145 1095
jrose@1145 1096 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
jrose@1145 1097 enum {
twisti@4866 1098 MN_IS_METHOD = 0x00010000, // method (not constructor)
twisti@4866 1099 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
twisti@4866 1100 MN_IS_FIELD = 0x00040000, // field
twisti@4866 1101 MN_IS_TYPE = 0x00080000, // nested type
twisti@4866 1102 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected
twisti@3969 1103 MN_REFERENCE_KIND_SHIFT = 24, // refKind
twisti@4866 1104 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
twisti@3969 1105 // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
twisti@4866 1106 MN_SEARCH_SUPERCLASSES = 0x00100000, // walk super classes
twisti@4866 1107 MN_SEARCH_INTERFACES = 0x00200000 // walk implemented interfaces
jrose@1145 1108 };
jrose@1145 1109
jrose@1145 1110 // Accessors for code generation:
jrose@1145 1111 static int clazz_offset_in_bytes() { return _clazz_offset; }
jrose@1145 1112 static int type_offset_in_bytes() { return _type_offset; }
jrose@1145 1113 static int name_offset_in_bytes() { return _name_offset; }
jrose@1145 1114 static int flags_offset_in_bytes() { return _flags_offset; }
jrose@1145 1115 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
jrose@1145 1116 static int vmindex_offset_in_bytes() { return _vmindex_offset; }
jrose@1145 1117 };
jrose@1145 1118
jrose@1145 1119
jrose@2639 1120 // Interface to java.lang.invoke.MethodType objects
jrose@1145 1121
jrose@2639 1122 class java_lang_invoke_MethodType: AllStatic {
jrose@1145 1123 friend class JavaClasses;
jrose@1145 1124
jrose@1145 1125 private:
jrose@1145 1126 static int _rtype_offset;
jrose@1145 1127 static int _ptypes_offset;
jrose@1145 1128
jrose@1145 1129 static void compute_offsets();
jrose@1145 1130
jrose@1145 1131 public:
jrose@1145 1132 // Accessors
jrose@1145 1133 static oop rtype(oop mt);
jrose@1145 1134 static objArrayOop ptypes(oop mt);
jrose@1145 1135
jrose@1145 1136 static oop ptype(oop mt, int index);
twisti@1568 1137 static int ptype_count(oop mt);
jrose@1145 1138
twisti@3969 1139 static int ptype_slot_count(oop mt); // extra counts for long/double
twisti@3969 1140 static int rtype_slot_count(oop mt); // extra counts for long/double
twisti@3969 1141
coleenp@2497 1142 static Symbol* as_signature(oop mt, bool intern_if_not_found, TRAPS);
jrose@1145 1143 static void print_signature(oop mt, outputStream* st);
jrose@1145 1144
jrose@1145 1145 static bool is_instance(oop obj) {
jrose@1145 1146 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
jrose@1145 1147 }
jrose@1145 1148
jrose@2982 1149 static bool equals(oop mt1, oop mt2);
jrose@2982 1150
jrose@1145 1151 // Accessors for code generation:
jrose@1145 1152 static int rtype_offset_in_bytes() { return _rtype_offset; }
jrose@1145 1153 static int ptypes_offset_in_bytes() { return _ptypes_offset; }
jrose@1145 1154 };
jrose@1145 1155
jrose@1145 1156
jrose@2639 1157 // Interface to java.lang.invoke.CallSite objects
jrose@1161 1158
jrose@2639 1159 class java_lang_invoke_CallSite: AllStatic {
jrose@1161 1160 friend class JavaClasses;
jrose@1161 1161
jrose@1161 1162 private:
jrose@1161 1163 static int _target_offset;
jrose@1161 1164
jrose@1161 1165 static void compute_offsets();
jrose@1161 1166
jrose@1161 1167 public:
jrose@1161 1168 // Accessors
twisti@3131 1169 static oop target( oop site) { return site->obj_field( _target_offset); }
twisti@3131 1170 static void set_target( oop site, oop target) { site->obj_field_put( _target_offset, target); }
jrose@1161 1171
twisti@3131 1172 static volatile oop target_volatile(oop site) { return site->obj_field_volatile( _target_offset); }
twisti@3131 1173 static void set_target_volatile(oop site, oop target) { site->obj_field_put_volatile(_target_offset, target); }
jrose@1862 1174
twisti@1570 1175 // Testers
coleenp@4037 1176 static bool is_subclass(Klass* klass) {
hseigel@4278 1177 return klass->is_subclass_of(SystemDictionary::CallSite_klass());
twisti@1570 1178 }
twisti@1570 1179 static bool is_instance(oop obj) {
twisti@1570 1180 return obj != NULL && is_subclass(obj->klass());
twisti@1570 1181 }
twisti@1570 1182
jrose@1161 1183 // Accessors for code generation:
jrose@1161 1184 static int target_offset_in_bytes() { return _target_offset; }
jrose@1161 1185 };
jrose@1145 1186
jrose@1145 1187
duke@435 1188 // Interface to java.security.AccessControlContext objects
duke@435 1189
duke@435 1190 class java_security_AccessControlContext: AllStatic {
duke@435 1191 private:
duke@435 1192 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
duke@435 1193 // so we compute the offsets at startup rather than hard-wiring them.
duke@435 1194 static int _context_offset;
duke@435 1195 static int _privilegedContext_offset;
duke@435 1196 static int _isPrivileged_offset;
mullan@5242 1197 static int _isAuthorized_offset;
duke@435 1198
duke@435 1199 static void compute_offsets();
duke@435 1200 public:
duke@435 1201 static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
duke@435 1202
mullan@5242 1203 static bool is_authorized(Handle context);
mullan@5242 1204
duke@435 1205 // Debugging/initialization
duke@435 1206 friend class JavaClasses;
duke@435 1207 };
duke@435 1208
duke@435 1209
duke@435 1210 // Interface to java.lang.ClassLoader objects
duke@435 1211
coleenp@4037 1212 #define CLASSLOADER_INJECTED_FIELDS(macro) \
coleenp@4304 1213 macro(java_lang_ClassLoader, loader_data, intptr_signature, false)
coleenp@4037 1214
duke@435 1215 class java_lang_ClassLoader : AllStatic {
duke@435 1216 private:
coleenp@4037 1217 // The fake offsets are added by the class loader when java.lang.Class is loaded
duke@435 1218 enum {
duke@435 1219 hc_parent_offset = 0
duke@435 1220 };
coleenp@4037 1221 static int _loader_data_offset;
never@3137 1222 static bool offsets_computed;
duke@435 1223 static int parent_offset;
never@3137 1224 static int parallelCapable_offset;
never@3137 1225
coleenp@4037 1226 public:
never@3137 1227 static void compute_offsets();
duke@435 1228
coleenp@4037 1229 static ClassLoaderData** loader_data_addr(oop loader);
coleenp@4037 1230 static ClassLoaderData* loader_data(oop loader);
coleenp@4037 1231
duke@435 1232 static oop parent(oop loader);
twisti@3969 1233 static bool isAncestor(oop loader, oop cl);
duke@435 1234
never@3137 1235 // Support for parallelCapable field
never@3137 1236 static bool parallelCapable(oop the_class_mirror);
never@3137 1237
duke@435 1238 static bool is_trusted_loader(oop loader);
duke@435 1239
duke@435 1240 // Fix for 4474172
duke@435 1241 static oop non_reflection_class_loader(oop loader);
duke@435 1242
twisti@3969 1243 // Testers
coleenp@4037 1244 static bool is_subclass(Klass* klass) {
hseigel@4278 1245 return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
twisti@3969 1246 }
twisti@3969 1247 static bool is_instance(oop obj) {
twisti@3969 1248 return obj != NULL && is_subclass(obj->klass());
twisti@3969 1249 }
twisti@3969 1250
duke@435 1251 // Debugging
duke@435 1252 friend class JavaClasses;
coleenp@4037 1253 friend class ClassFileParser; // access to number_of_fake_fields
duke@435 1254 };
duke@435 1255
duke@435 1256
duke@435 1257 // Interface to java.lang.System objects
duke@435 1258
duke@435 1259 class java_lang_System : AllStatic {
duke@435 1260 private:
duke@435 1261 enum {
duke@435 1262 hc_static_in_offset = 0,
duke@435 1263 hc_static_out_offset = 1,
mullan@5242 1264 hc_static_err_offset = 2,
mullan@5242 1265 hc_static_security_offset = 3
duke@435 1266 };
duke@435 1267
duke@435 1268 static int static_in_offset;
duke@435 1269 static int static_out_offset;
duke@435 1270 static int static_err_offset;
mullan@5242 1271 static int static_security_offset;
duke@435 1272
duke@435 1273 public:
duke@435 1274 static int in_offset_in_bytes();
duke@435 1275 static int out_offset_in_bytes();
duke@435 1276 static int err_offset_in_bytes();
duke@435 1277
mullan@5242 1278 static bool has_security_manager();
mullan@5242 1279
duke@435 1280 // Debugging
duke@435 1281 friend class JavaClasses;
duke@435 1282 };
duke@435 1283
duke@435 1284
duke@435 1285 // Interface to java.lang.StackTraceElement objects
duke@435 1286
duke@435 1287 class java_lang_StackTraceElement: AllStatic {
duke@435 1288 private:
duke@435 1289 enum {
duke@435 1290 hc_declaringClass_offset = 0,
duke@435 1291 hc_methodName_offset = 1,
duke@435 1292 hc_fileName_offset = 2,
duke@435 1293 hc_lineNumber_offset = 3
duke@435 1294 };
duke@435 1295
duke@435 1296 static int declaringClass_offset;
duke@435 1297 static int methodName_offset;
duke@435 1298 static int fileName_offset;
duke@435 1299 static int lineNumber_offset;
duke@435 1300
duke@435 1301 public:
duke@435 1302 // Setters
duke@435 1303 static void set_declaringClass(oop element, oop value);
duke@435 1304 static void set_methodName(oop element, oop value);
duke@435 1305 static void set_fileName(oop element, oop value);
duke@435 1306 static void set_lineNumber(oop element, int value);
duke@435 1307
duke@435 1308 // Create an instance of StackTraceElement
coleenp@4466 1309 static oop create(Handle mirror, int method, int version, int bci, TRAPS);
coleenp@4466 1310 static oop create(methodHandle method, int bci, TRAPS);
duke@435 1311
duke@435 1312 // Debugging
duke@435 1313 friend class JavaClasses;
duke@435 1314 };
duke@435 1315
duke@435 1316
duke@435 1317 // Interface to java.lang.AssertionStatusDirectives objects
duke@435 1318
duke@435 1319 class java_lang_AssertionStatusDirectives: AllStatic {
duke@435 1320 private:
duke@435 1321 enum {
duke@435 1322 hc_classes_offset,
duke@435 1323 hc_classEnabled_offset,
duke@435 1324 hc_packages_offset,
duke@435 1325 hc_packageEnabled_offset,
duke@435 1326 hc_deflt_offset
duke@435 1327 };
duke@435 1328
duke@435 1329 static int classes_offset;
duke@435 1330 static int classEnabled_offset;
duke@435 1331 static int packages_offset;
duke@435 1332 static int packageEnabled_offset;
duke@435 1333 static int deflt_offset;
duke@435 1334
duke@435 1335 public:
duke@435 1336 // Setters
duke@435 1337 static void set_classes(oop obj, oop val);
duke@435 1338 static void set_classEnabled(oop obj, oop val);
duke@435 1339 static void set_packages(oop obj, oop val);
duke@435 1340 static void set_packageEnabled(oop obj, oop val);
duke@435 1341 static void set_deflt(oop obj, bool val);
duke@435 1342 // Debugging
duke@435 1343 friend class JavaClasses;
duke@435 1344 };
duke@435 1345
duke@435 1346
duke@435 1347 class java_nio_Buffer: AllStatic {
duke@435 1348 private:
duke@435 1349 static int _limit_offset;
duke@435 1350
duke@435 1351 public:
duke@435 1352 static int limit_offset();
duke@435 1353 static void compute_offsets();
duke@435 1354 };
duke@435 1355
duke@435 1356 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
duke@435 1357 private:
duke@435 1358 static int _owner_offset;
duke@435 1359 public:
duke@435 1360 static void initialize(TRAPS);
duke@435 1361 static oop get_owner_threadObj(oop obj);
duke@435 1362 };
duke@435 1363
never@3137 1364 // Use to declare fields that need to be injected into Java classes
never@3137 1365 // for the JVM to use. The name_index and signature_index are
never@3137 1366 // declared in vmSymbols. The may_be_java flag is used to declare
never@3137 1367 // fields that might already exist in Java but should be injected if
never@3137 1368 // they don't. Otherwise the field is unconditionally injected and
never@3137 1369 // the JVM uses the injected one. This is to ensure that name
never@3137 1370 // collisions don't occur. In general may_be_java should be false
never@3137 1371 // unless there's a good reason.
never@3137 1372
never@3137 1373 class InjectedField {
never@3137 1374 public:
never@3137 1375 const SystemDictionary::WKID klass_id;
never@3137 1376 const vmSymbols::SID name_index;
never@3137 1377 const vmSymbols::SID signature_index;
never@3137 1378 const bool may_be_java;
never@3137 1379
never@3137 1380
coleenp@4037 1381 Klass* klass() const { return SystemDictionary::well_known_klass(klass_id); }
never@3137 1382 Symbol* name() const { return lookup_symbol(name_index); }
never@3137 1383 Symbol* signature() const { return lookup_symbol(signature_index); }
never@3137 1384
never@3137 1385 int compute_offset();
never@3137 1386
never@3137 1387 // Find the Symbol for this index
never@3137 1388 static Symbol* lookup_symbol(int symbol_index) {
never@3137 1389 return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
never@3137 1390 }
never@3137 1391 };
never@3137 1392
never@3137 1393 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
never@3137 1394 klass##_##name##_enum,
never@3137 1395
never@3137 1396 #define ALL_INJECTED_FIELDS(macro) \
never@3137 1397 CLASS_INJECTED_FIELDS(macro) \
coleenp@4037 1398 CLASSLOADER_INJECTED_FIELDS(macro) \
twisti@3969 1399 MEMBERNAME_INJECTED_FIELDS(macro)
never@3137 1400
duke@435 1401 // Interface to hard-coded offset checking
duke@435 1402
duke@435 1403 class JavaClasses : AllStatic {
duke@435 1404 private:
never@3137 1405
never@3137 1406 static InjectedField _injected_fields[];
never@3137 1407
duke@435 1408 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
duke@435 1409 static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
jrose@567 1410 static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
never@3137 1411
duke@435 1412 public:
never@3137 1413 enum InjectedFieldID {
never@3137 1414 ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
never@3137 1415 MAX_enum
never@3137 1416 };
never@3137 1417
never@3137 1418 static int compute_injected_offset(InjectedFieldID id);
never@3137 1419
duke@435 1420 static void compute_hard_coded_offsets();
duke@435 1421 static void compute_offsets();
duke@435 1422 static void check_offsets() PRODUCT_RETURN;
never@3137 1423
never@3137 1424 static InjectedField* get_injected(Symbol* class_name, int* field_count);
duke@435 1425 };
stefank@2314 1426
never@3137 1427 #undef DECLARE_INJECTED_FIELD_ENUM
never@3137 1428
stefank@2314 1429 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP

mercurial