src/share/vm/classfile/javaClasses.hpp

Wed, 02 May 2012 13:21:36 -0400

author
jiangli
date
Wed, 02 May 2012 13:21:36 -0400
changeset 3741
8bafad97cd26
parent 3205
e5928e7dab26
child 3760
8f972594effc
permissions
-rw-r--r--

7158552: The instanceKlsss::_host_klass is only needed for anonymous class for JSR 292 support.
Summary: Change the _host_klass to be conditionally created embedded instanceKlass field.
Reviewed-by: jrose, coleenp, dholmes

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

mercurial