1 /*
2 * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_CLASSFILE_JAVACLASSES_HPP
26 #define SHARE_CLASSFILE_JAVACLASSES_HPP
27
28 #include "classfile/vmClasses.hpp"
29 #include "oops/instanceKlass.hpp"
30 #include "oops/oopsHierarchy.hpp"
31 #include "oops/symbol.hpp"
32 #include "runtime/handles.hpp"
33 #include "runtime/os.hpp"
34 #include "utilities/macros.hpp"
35 #include "utilities/utf8.hpp"
36 #include "utilities/vmEnums.hpp"
37
38 class JvmtiThreadState;
39 class RecordComponent;
40 class SerializeClosure;
41 class ObjectWaiter;
42 class ObjectMonitor;
43
44 #define CHECK_INIT(offset) assert(offset != 0, "should be initialized"); return offset;
45
46 // Interface to java.lang.Object objects
47
48 class java_lang_Object : AllStatic {
49 public:
50 static void register_natives(TRAPS);
51 };
52
53 // Interface to java.lang.String objects
54
55 // The flags field is a collection of bits representing boolean values used
56 // internally by the VM.
57 #define STRING_INJECTED_FIELDS(macro) \
58 macro(java_lang_String, flags, byte_signature, false)
59
60 class java_lang_String : AllStatic {
61 private:
62 static int _value_offset;
63 static int _hash_offset;
64 static int _hashIsZero_offset;
65 static int _coder_offset;
66 static int _flags_offset;
67
68 static bool _initialized;
69
70 static Handle basic_create(int length, bool byte_arr, TRAPS);
71
72 static inline void set_coder(oop string, jbyte coder);
73
74 // Bitmasks for values in the injected flags field.
75 static const uint8_t _deduplication_forbidden_mask = 1 << 0;
76 static const uint8_t _deduplication_requested_mask = 1 << 1;
77
78 static int flags_offset() { CHECK_INIT(_flags_offset); }
79 // Return the address of the injected flags field.
80 static inline uint8_t* flags_addr(oop java_string);
81 // Test whether the designated bit of the injected flags field is set.
82 static inline bool is_flag_set(oop java_string, uint8_t flag_mask);
83 // Atomically test and set the designated bit of the injected flags field,
84 // returning true if the bit was already set.
85 static bool test_and_set_flag(oop java_string, uint8_t flag_mask);
86
87 static inline unsigned int hash_code_impl(oop java_string, bool update);
88
89 public:
90
91 // Coders
92 enum Coder {
93 CODER_LATIN1 = 0,
94 CODER_UTF16 = 1
95 };
96
97 static void compute_offsets();
98 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
99
100 // Instance creation
101 static Handle create_from_unicode(const jchar* unicode, int len, TRAPS);
102 static oop create_oop_from_unicode(const jchar* unicode, int len, TRAPS);
103 static Handle create_from_str(const char* utf8_str, TRAPS);
104 static oop create_oop_from_str(const char* utf8_str, TRAPS);
105 static Handle create_from_symbol(const Symbol* symbol, TRAPS);
106 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
107
108 static void set_compact_strings(bool value);
109
110 static int value_offset() { CHECK_INIT(_value_offset); }
111 static int coder_offset() { CHECK_INIT(_coder_offset); }
112
113 static inline void set_value(oop string, typeArrayOop buffer);
114
115 // Set the deduplication_forbidden flag true. This flag is sticky; once
116 // set it never gets cleared. This is set when a String is interned in
117 // the StringTable, to prevent string deduplication from changing the
118 // String's value array.
119 static inline void set_deduplication_forbidden(oop java_string);
120
121 // Test and set the deduplication_requested flag. Returns the old value
122 // of the flag. This flag is sticky; once set it never gets cleared.
123 // Some GCs may use this flag when deciding whether to request
124 // deduplication of a String, to avoid multiple requests for the same
125 // object.
126 static inline bool test_and_set_deduplication_requested(oop java_string);
127
128 // Accessors
129 static inline typeArrayOop value(oop java_string);
130 static inline typeArrayOop value_no_keepalive(oop java_string);
131 static inline bool hash_is_set(oop string);
132 static inline bool is_latin1(oop java_string);
133 static inline bool deduplication_forbidden(oop java_string);
134 static inline bool deduplication_requested(oop java_string);
135 static inline int length(oop java_string);
136 static inline int length(oop java_string, typeArrayOop string_value);
137 static size_t utf8_length(oop java_string);
138 static size_t utf8_length(oop java_string, typeArrayOop string_value);
139 // Legacy variants that truncate the length if needed
140 static int utf8_length_as_int(oop java_string);
141 static int utf8_length_as_int(oop java_string, typeArrayOop string_value);
142
143 // String converters
144 static char* as_utf8_string(oop java_string);
145 // `length` is set to the length of the utf8 sequence.
146 static char* as_utf8_string(oop java_string, size_t& length);
147 static char* as_utf8_string_full(oop java_string, char* buf, size_t buflen, size_t& length);
148 static char* as_utf8_string(oop java_string, char* buf, size_t buflen);
149 static char* as_utf8_string(oop java_string, int start, int len);
150 static char* as_utf8_string(oop java_string, typeArrayOop value, char* buf, size_t buflen);
151 static char* as_utf8_string(oop java_string, typeArrayOop value, int start, int len, char* buf, size_t buflen);
152 static char* as_platform_dependent_str(Handle java_string, TRAPS);
153 static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
154 static jchar* as_unicode_string_or_null(oop java_string, int& length);
155 // produce an ascii string with all other values quoted using \u####
156 static char* as_quoted_ascii(oop java_string);
157
158 // Compute the hash value for a java.lang.String object which would
159 // contain the characters passed in.
160 //
161 // As the hash value used by the String object itself, in
162 // String.hashCode(). This value is normally calculated in Java code
163 // in the String.hashCode method(), but is precomputed for String
164 // objects in the shared archive file.
165 // hash P(31) from Kernighan & Ritchie
166 //
167 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
168 static unsigned int hash_code(const jchar* s, int len) {
169 unsigned int h = 0;
170 while (len-- > 0) {
171 h = 31*h + (unsigned int) *s;
172 s++;
173 }
174 return h;
175 }
176
177 static unsigned int hash_code(const jbyte* s, int len) {
178 unsigned int h = 0;
179 while (len-- > 0) {
180 h = 31*h + (((unsigned int) *s) & 0xFF);
181 s++;
182 }
183 return h;
184 }
185
186 static unsigned int hash_code(const char* utf8_str, size_t utf8_len) {
187 unsigned int h = 0;
188 int unicode_length = UTF8::unicode_length(utf8_str, utf8_len);
189
190 jchar c;
191 while (unicode_length-- > 0) {
192 utf8_str = UTF8::next(utf8_str, &c);
193 h = 31 * h + ((unsigned int)c);
194 }
195 return h;
196 }
197
198 static unsigned int hash_code(oop java_string);
199 static unsigned int hash_code_noupdate(oop java_string);
200
201 // Compare strings (of different types/encodings), length is the string (array) length
202 static bool equals(oop java_string, const jchar* chars, int len);
203 static bool equals(oop java_string, const char* utf8_str, size_t utf8_len);
204 static bool equals(oop str1, oop str2);
205 static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2);
206
207 // Conversion between '.' and '/' formats, and allocate a String from the result.
208 static Handle externalize_classname(Symbol* java_name, TRAPS);
209
210 // Conversion
211 static Symbol* as_symbol(oop java_string);
212 static Symbol* as_symbol_or_null(oop java_string);
213
214 // Tester
215 static inline bool is_instance(oop obj);
216
217 // Debugging
218 static void print(oop java_string, outputStream* st, int max_length = MaxStringPrintSize);
219 friend class JavaClasses;
220 friend class StringTable;
221 };
222
223
224 // Interface to java.lang.Class objects
225
226 #define CLASS_INJECTED_FIELDS(macro) \
227 macro(java_lang_Class, klass, intptr_signature, false) \
228 macro(java_lang_Class, array_klass, intptr_signature, false) \
229 macro(java_lang_Class, oop_size, int_signature, false) \
230 macro(java_lang_Class, static_oop_field_count, int_signature, false) \
231 macro(java_lang_Class, source_file, object_signature, false) \
232 macro(java_lang_Class, init_lock, object_signature, false)
233
234 class java_lang_Class : AllStatic {
235 friend class VMStructs;
236 friend class JVMCIVMStructs;
237 friend class HeapShared;
238
239 private:
240
241 // The fake offsets are added by the class loader when java.lang.Class is loaded
242
243 static int _klass_offset;
244 static int _array_klass_offset;
245
246 static int _oop_size_offset;
247 static int _static_oop_field_count_offset;
248
249 static int _protection_domain_offset;
250 static int _init_lock_offset;
251 static int _signers_offset;
252 static int _class_loader_offset;
253 static int _module_offset;
254 static int _component_mirror_offset;
255 static int _name_offset;
256 static int _source_file_offset;
257 static int _classData_offset;
258 static int _classRedefinedCount_offset;
259 static int _reflectionData_offset;
260 static int _modifiers_offset;
261 static int _is_primitive_offset;
262 static int _raw_access_flags_offset;
263
264 static bool _offsets_computed;
265
266 static GrowableArray<Klass*>* _fixup_mirror_list;
267 static GrowableArray<Klass*>* _fixup_module_field_list;
268
269 static void set_init_lock(oop java_class, oop init_lock);
270 static void set_protection_domain(oop java_class, oop protection_domain);
271 static void set_class_loader(oop java_class, oop class_loader);
272 static void set_component_mirror(oop java_class, oop comp_mirror);
273 static void initialize_mirror_fields(InstanceKlass* ik, Handle mirror, Handle protection_domain,
274 Handle classData, TRAPS);
275 static void set_mirror_module_field(JavaThread* current, Klass* K, Handle mirror, Handle module);
276
277 static void set_modifiers(oop java_class, u2 value);
278 static void set_raw_access_flags(oop java_class, u2 value);
279 static void set_is_primitive(oop java_class);
280 static void release_set_array_klass(oop java_class, Klass* klass);
281
282 public:
283 static void allocate_fixup_lists();
284 static void compute_offsets();
285
286 // Instance creation
287 static void allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
288 Handle& mirror, Handle& comp_mirror, TRAPS); // returns mirror and comp_mirror
289 static void create_mirror(Klass* k, Handle class_loader, Handle module,
290 Handle protection_domain, Handle classData, TRAPS);
291 static void fixup_mirror(Klass* k, TRAPS);
292 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
293
294 // Archiving
295 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
296 static void create_scratch_mirror(Klass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
297 static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module,
298 Handle protection_domain,
299 TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(false);
300
301 static void fixup_module_field(Klass* k, Handle module);
302
303 // Conversion -- java_class must not be null. The return value is null only if java_class is a primitive type.
304 static Klass* as_Klass(oop java_class);
305 static InstanceKlass* as_InstanceKlass(oop java_class);
306
307 static void set_klass(oop java_class, Klass* klass);
308 static BasicType as_BasicType(oop java_class, Klass** reference_klass = nullptr);
309 static Symbol* as_signature(oop java_class, bool intern_if_not_found);
310 static void print_signature(oop java_class, outputStream *st);
311 static const char* as_external_name(oop java_class);
312 // Testing
313 static bool is_instance(oop obj);
314
315 static bool is_primitive(oop java_class);
316 static BasicType primitive_type(oop java_class);
317 static oop primitive_mirror(BasicType t);
318 static Klass* array_klass_acquire(oop java_class);
319
320 // compiler support for class operations
321 static int klass_offset() { CHECK_INIT(_klass_offset); }
322 static int array_klass_offset() { CHECK_INIT(_array_klass_offset); }
323 // Support for classRedefinedCount field
324 static int classRedefinedCount(oop the_class_mirror);
325 static void set_classRedefinedCount(oop the_class_mirror, int value);
326
327 // Support for embedded per-class oops
328 static oop protection_domain(oop java_class);
329 static oop init_lock(oop java_class);
330 static void clear_init_lock(oop java_class) {
331 set_init_lock(java_class, nullptr);
332 }
333 static oop component_mirror(oop java_class);
334 static int component_mirror_offset() { return _component_mirror_offset; }
335 static objArrayOop signers(oop java_class);
336 static oop class_data(oop java_class);
337 static void set_class_data(oop java_class, oop classData);
338 static int reflection_data_offset() { return _reflectionData_offset; }
339
340 static oop class_loader(oop java_class);
341 static void set_module(oop java_class, oop module);
342 static oop module(oop java_class);
343
344 static oop name(Handle java_class, TRAPS);
345
346 static oop source_file(oop java_class);
347 static void set_source_file(oop java_class, oop source_file);
348
349 static int modifiers(oop java_class);
350
351 static size_t oop_size(oop java_class);
352 static void set_oop_size(HeapWord* java_class, size_t size);
353 static int static_oop_field_count(oop java_class);
354 static void set_static_oop_field_count(oop java_class, int size);
355
356 static GrowableArray<Klass*>* fixup_mirror_list() {
357 return _fixup_mirror_list;
358 }
359 static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
360 _fixup_mirror_list = v;
361 }
362
363 static GrowableArray<Klass*>* fixup_module_field_list() {
364 return _fixup_module_field_list;
365 }
366 static void set_fixup_module_field_list(GrowableArray<Klass*>* v) {
367 _fixup_module_field_list = v;
368 }
369
370 // Debugging
371 friend class JavaClasses;
372 };
373
374 // Interface to java.lang.Thread objects
375
376 #define THREAD_INJECTED_FIELDS(macro) \
377 macro(java_lang_Thread, jvmti_thread_state, intptr_signature, false) \
378 macro(java_lang_Thread, vthread_transition_disable_count, int_signature, false) \
379 macro(java_lang_Thread, is_in_vthread_transition, bool_signature, false) \
380 JFR_ONLY(macro(java_lang_Thread, jfr_epoch, short_signature, false))
381
382 class java_lang_Thread : AllStatic {
383 friend class java_lang_VirtualThread;
384 friend class JVMCIVMStructs;
385 private:
386 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
387 // so we compute the offsets at startup rather than hard-wiring them.
388 static int _holder_offset;
389 static int _name_offset;
390 static int _contextClassLoader_offset;
391 static int _eetop_offset;
392 static int _jvmti_thread_state_offset;
393 static int _vthread_transition_disable_count_offset;
394 static int _is_in_vthread_transition_offset;
395 static int _interrupted_offset;
396 static int _interruptLock_offset;
397 static int _tid_offset;
398 static int _continuation_offset;
399 static int _park_blocker_offset;
400 static int _scopedValueBindings_offset;
401 JFR_ONLY(static int _jfr_epoch_offset;)
402
403 static void compute_offsets();
404
405 public:
406 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
407
408 // Returns the JavaThread associated with the thread obj
409 static JavaThread* thread(oop java_thread);
410 static JavaThread* thread_acquire(oop java_thread);
411 // Set JavaThread for instance
412 static void set_thread(oop java_thread, JavaThread* thread);
413 static void release_set_thread(oop java_thread, JavaThread* thread);
414 // FieldHolder
415 static oop holder(oop java_thread);
416 // interruptLock
417 static oop interrupt_lock(oop java_thread);
418 // Interrupted status
419 static bool interrupted(oop java_thread);
420 static void set_interrupted(oop java_thread, bool val);
421 // Name
422 static oop name(oop java_thread);
423 static void set_name(oop java_thread, oop name);
424 // Priority
425 static ThreadPriority priority(oop java_thread);
426 static void set_priority(oop java_thread, ThreadPriority priority);
427 // Thread group
428 static oop threadGroup(oop java_thread);
429 // Alive (NOTE: this is not really a field, but provides the correct
430 // definition without doing a Java call)
431 static bool is_alive(oop java_thread);
432 // Daemon
433 static bool is_daemon(oop java_thread);
434 static void set_daemon(oop java_thread);
435 // Context ClassLoader
436 static oop context_class_loader(oop java_thread);
437 // Stack size hint
438 static jlong stackSize(oop java_thread);
439 // Thread ID
440 static int64_t thread_id(oop java_thread);
441 static ByteSize thread_id_offset();
442 // Continuation
443 static inline oop continuation(oop java_thread);
444
445 static JvmtiThreadState* jvmti_thread_state(oop java_thread);
446 static void set_jvmti_thread_state(oop java_thread, JvmtiThreadState* state);
447
448 static int vthread_transition_disable_count(oop java_thread);
449 static void inc_vthread_transition_disable_count(oop java_thread);
450 static void dec_vthread_transition_disable_count(oop java_thread);
451 static int vthread_transition_disable_count_offset() { return _vthread_transition_disable_count_offset; }
452
453 static bool is_in_vthread_transition(oop java_thread);
454 static void set_is_in_vthread_transition(oop java_thread, bool val);
455 static int is_in_vthread_transition_offset() { return _is_in_vthread_transition_offset; }
456
457 // Clear all scoped value bindings on error
458 static void clear_scopedValueBindings(oop java_thread);
459
460 // Blocker object responsible for thread parking
461 static oop park_blocker(oop java_thread);
462
463 // Write thread status info to threadStatus field of java.lang.Thread.
464 static void set_thread_status(oop java_thread_oop, JavaThreadStatus status);
465 // Read thread status info from threadStatus field of java.lang.Thread.
466 static JavaThreadStatus get_thread_status(oop java_thread_oop);
467
468 static const char* thread_status_name(oop java_thread_oop);
469
470 // Fill in current stack trace, can cause GC
471 static oop async_get_stack_trace(jobject jthread, TRAPS);
472
473 JFR_ONLY(static u2 jfr_epoch(oop java_thread);)
474 JFR_ONLY(static void set_jfr_epoch(oop java_thread, u2 epoch);)
475 JFR_ONLY(static int jfr_epoch_offset() { CHECK_INIT(_jfr_epoch_offset); })
476
477 // Debugging
478 friend class JavaClasses;
479 };
480
481 // Interface to java.lang.Thread$FieldHolder objects
482
483 class java_lang_Thread_FieldHolder : AllStatic {
484 private:
485 static int _group_offset;
486 static int _priority_offset;
487 static int _stackSize_offset;
488 static int _daemon_offset;
489 static int _thread_status_offset;
490
491 static void compute_offsets();
492
493 public:
494 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
495
496 static oop threadGroup(oop holder);
497
498 static ThreadPriority priority(oop holder);
499 static void set_priority(oop holder, ThreadPriority priority);
500
501 static jlong stackSize(oop holder);
502
503 static bool is_daemon(oop holder);
504 static void set_daemon(oop holder, bool val);
505
506 static void set_thread_status(oop holder, JavaThreadStatus status);
507 static JavaThreadStatus get_thread_status(oop holder);
508
509 friend class JavaClasses;
510 };
511
512 // Interface to java.lang.Thread$Constants objects
513
514 class java_lang_Thread_Constants : AllStatic {
515 private:
516 static int _static_VTHREAD_GROUP_offset;
517 static int _static_NOT_SUPPORTED_CLASSLOADER_offset;
518
519 static void compute_offsets();
520 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
521
522 public:
523 static oop get_VTHREAD_GROUP();
524
525 friend class JavaClasses;
526 };
527
528 // Interface to java.lang.ThreadGroup objects
529
530 class java_lang_ThreadGroup : AllStatic {
531 private:
532 static int _parent_offset;
533 static int _name_offset;
534 static int _maxPriority_offset;
535 static int _daemon_offset;
536
537 static void compute_offsets();
538 public:
539 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
540
541 // parent ThreadGroup
542 static oop parent(oop java_thread_group);
543 // name
544 static const char* name(oop java_thread_group);
545 // maxPriority in group
546 static ThreadPriority maxPriority(oop java_thread_group);
547 // Daemon
548 static bool is_daemon(oop java_thread_group);
549
550 // Debugging
551 friend class JavaClasses;
552 };
553
554
555 // Interface to java.lang.VirtualThread objects
556 #define VTHREAD_INJECTED_FIELDS(macro) \
557 macro(java_lang_VirtualThread, objectWaiter, intptr_signature, false)
558
559 class java_lang_VirtualThread : AllStatic {
560 private:
561 static int static_vthread_scope_offset;
562 static int _carrierThread_offset;
563 static int _continuation_offset;
564 static int _state_offset;
565 static int _next_offset;
566 static int _onWaitingList_offset;
567 static int _notified_offset;
568 static int _interruptible_wait_offset;
569 static int _recheckInterval_offset;
570 static int _timeout_offset;
571 static int _objectWaiter_offset;
572 JFR_ONLY(static int _jfr_epoch_offset;)
573 public:
574 enum {
575 NEW = 0,
576 STARTED = 1,
577 RUNNING = 2,
578 PARKING = 3,
579 PARKED = 4,
580 PINNED = 5,
581 TIMED_PARKING = 6,
582 TIMED_PARKED = 7,
583 TIMED_PINNED = 8,
584 UNPARKED = 9,
585 YIELDING = 10,
586 YIELDED = 11,
587 BLOCKING = 12,
588 BLOCKED = 13,
589 UNBLOCKED = 14,
590 WAITING = 15,
591 WAIT = 16, // waiting in Object.wait
592 TIMED_WAITING = 17,
593 TIMED_WAIT = 18, // waiting in timed-Object.wait
594 TERMINATED = 99,
595 };
596
597 static void compute_offsets();
598 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
599
600 // Testers
601 static bool is_subclass(Klass* klass) {
602 return klass->is_subclass_of(vmClasses::VirtualThread_klass());
603 }
604 static bool is_instance(oop obj);
605
606 static oop vthread_scope();
607 static oop carrier_thread(oop vthread);
608 static oop continuation(oop vthread);
609 static int state(oop vthread);
610 static void set_state(oop vthread, int state);
611 static int cmpxchg_state(oop vthread, int old_state, int new_state);
612 static oop next(oop vthread);
613 static void set_next(oop vthread, oop next_vthread);
614 static bool set_onWaitingList(oop vthread, OopHandle& list_head);
615 static jlong timeout(oop vthread);
616 static void set_timeout(oop vthread, jlong value);
617 static void set_notified(oop vthread, jboolean value);
618 static void set_interruptible_wait(oop vthread, jboolean value);
619 static bool is_preempted(oop vthread);
620 static JavaThreadStatus map_state_to_thread_status(int state);
621
622 static inline ObjectWaiter* objectWaiter(oop vthread);
623 static inline void set_objectWaiter(oop vthread, ObjectWaiter* waiter);
624 static ObjectMonitor* current_pending_monitor(oop vthread);
625 static ObjectMonitor* current_waiting_monitor(oop vthread);
626 };
627
628
629 // Interface to java.lang.Throwable objects
630
631 class java_lang_Throwable: AllStatic {
632 friend class BacktraceBuilder;
633 friend class BacktraceIterator;
634
635 private:
636 // Trace constants
637 enum {
638 trace_methods_offset = 0,
639 trace_bcis_offset = 1,
640 trace_mirrors_offset = 2,
641 trace_names_offset = 3,
642 trace_conts_offset = 4,
643 trace_next_offset = 5,
644 trace_hidden_offset = 6,
645 trace_size = 7,
646 trace_chunk_size = 32
647 };
648
649 static int _backtrace_offset;
650 static int _detailMessage_offset;
651 static int _stackTrace_offset;
652 static int _depth_offset;
653 static int _cause_offset;
654 static int _static_unassigned_stacktrace_offset;
655
656 // StackTrace (programmatic access, new since 1.4)
657 static void clear_stacktrace(oop throwable);
658 // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
659 static void set_stacktrace(oop throwable, oop st_element_array);
660 static oop unassigned_stacktrace();
661
662 public:
663 // Backtrace
664 static oop backtrace(oop throwable);
665 static void set_backtrace(oop throwable, oop value);
666 static int depth(oop throwable);
667 static void set_depth(oop throwable, int value);
668 // Message
669 static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); }
670 static oop message(oop throwable);
671 static const char* message_as_utf8(oop throwable);
672 static void set_message(oop throwable, oop value);
673
674 static oop cause(oop throwable);
675
676 static void print_stack_element(outputStream *st, Method* method, int bci);
677
678 static void compute_offsets();
679 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
680
681 // Allocate space for backtrace (created but stack trace not filled in)
682 static void allocate_backtrace(Handle throwable, TRAPS);
683 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
684 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
685 // Fill in current stack trace, can cause GC
686 static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
687 static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
688
689 // Programmatic access to stack trace
690 static void get_stack_trace_elements(int depth, Handle backtrace, objArrayHandle stack_trace, TRAPS);
691
692 // For recreating class initialization error exceptions.
693 static Handle create_initialization_error(JavaThread* current, Handle throwable);
694
695 // Printing
696 static void print(oop throwable, outputStream* st);
697 static void print_stack_trace(Handle throwable, outputStream* st);
698 static void java_printStackTrace(Handle throwable, TRAPS);
699 // Debugging
700 friend class JavaClasses;
701 // Gets the method and bci of the top frame (TOS). Returns false if this failed.
702 static bool get_top_method_and_bci(oop throwable, Method** method, int* bci);
703 };
704
705
706 // Interface to java.lang.reflect.AccessibleObject objects
707
708 class java_lang_reflect_AccessibleObject: AllStatic {
709 private:
710 // Note that to reduce dependencies on the JDK we compute these
711 // offsets at run-time.
712 static int _override_offset;
713
714 static void compute_offsets();
715
716 public:
717 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
718
719 // Accessors
720 static jboolean override(oop reflect);
721 static void set_override(oop reflect, jboolean value);
722
723 // Debugging
724 friend class JavaClasses;
725 };
726
727
728 // Interface to java.lang.reflect.Method objects
729
730 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
731 private:
732 // Note that to reduce dependencies on the JDK we compute these
733 // offsets at run-time.
734 static int _clazz_offset;
735 static int _name_offset;
736 static int _returnType_offset;
737 static int _parameterTypes_offset;
738 static int _exceptionTypes_offset;
739 static int _slot_offset;
740 static int _modifiers_offset;
741 static int _signature_offset;
742 static int _annotations_offset;
743 static int _parameter_annotations_offset;
744 static int _annotation_default_offset;
745
746 static void compute_offsets();
747 public:
748 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
749
750 // Allocation
751 static Handle create(TRAPS);
752
753 // Accessors
754 static oop clazz(oop reflect);
755 static void set_clazz(oop reflect, oop value);
756
757 static void set_name(oop method, oop value);
758
759 static oop return_type(oop method);
760 static void set_return_type(oop method, oop value);
761
762 static oop parameter_types(oop method);
763 static void set_parameter_types(oop method, oop value);
764
765 static int slot(oop reflect);
766 static void set_slot(oop reflect, int value);
767
768 static void set_exception_types(oop method, oop value);
769 static void set_modifiers(oop method, int value);
770 static void set_signature(oop method, oop value);
771 static void set_annotations(oop method, oop value);
772 static void set_parameter_annotations(oop method, oop value);
773 static void set_annotation_default(oop method, oop value);
774
775 // Debugging
776 friend class JavaClasses;
777 };
778
779
780 // Interface to java.lang.reflect.Constructor objects
781
782 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
783 private:
784 // Note that to reduce dependencies on the JDK we compute these
785 // offsets at run-time.
786 static int _clazz_offset;
787 static int _parameterTypes_offset;
788 static int _exceptionTypes_offset;
789 static int _slot_offset;
790 static int _modifiers_offset;
791 static int _signature_offset;
792 static int _annotations_offset;
793 static int _parameter_annotations_offset;
794
795 static void compute_offsets();
796 public:
797 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
798
799 // Allocation
800 static Handle create(TRAPS);
801
802 // Accessors
803 static oop clazz(oop reflect);
804 static void set_clazz(oop reflect, oop value);
805
806 static oop parameter_types(oop constructor);
807 static void set_parameter_types(oop constructor, oop value);
808
809 static int slot(oop reflect);
810 static void set_slot(oop reflect, int value);
811
812 static void set_exception_types(oop constructor, oop value);
813 static void set_modifiers(oop constructor, int value);
814 static void set_signature(oop constructor, oop value);
815 static void set_annotations(oop constructor, oop value);
816 static void set_parameter_annotations(oop method, oop value);
817
818 // Debugging
819 friend class JavaClasses;
820 };
821
822
823 // Interface to java.lang.reflect.Field objects
824
825 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
826 private:
827 // Note that to reduce dependencies on the JDK we compute these
828 // offsets at run-time.
829 static int _clazz_offset;
830 static int _name_offset;
831 static int _type_offset;
832 static int _slot_offset;
833 static int _modifiers_offset;
834 static int _trusted_final_offset;
835 static int _signature_offset;
836 static int _annotations_offset;
837
838 static void compute_offsets();
839
840 public:
841 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
842
843 // Allocation
844 static Handle create(TRAPS);
845
846 // Accessors
847 static oop clazz(oop reflect);
848 static void set_clazz(oop reflect, oop value);
849
850 static oop name(oop field);
851 static void set_name(oop field, oop value);
852
853 static oop type(oop field);
854 static void set_type(oop field, oop value);
855
856 static int slot(oop reflect);
857 static void set_slot(oop reflect, int value);
858
859 static int modifiers(oop field);
860 static void set_modifiers(oop field, int value);
861
862 static void set_trusted_final(oop field);
863
864 static void set_signature(oop constructor, oop value);
865 static void set_annotations(oop constructor, oop value);
866
867 // Debugging
868 friend class JavaClasses;
869 };
870
871 class java_lang_reflect_Parameter {
872 private:
873 // Note that to reduce dependencies on the JDK we compute these
874 // offsets at run-time.
875 static int _name_offset;
876 static int _modifiers_offset;
877 static int _index_offset;
878 static int _executable_offset;
879
880 static void compute_offsets();
881
882 public:
883 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
884
885 // Allocation
886 static Handle create(TRAPS);
887
888 // Accessors
889 static oop name(oop field);
890 static void set_name(oop field, oop value);
891
892 static int index(oop reflect);
893 static void set_index(oop reflect, int value);
894
895 static int modifiers(oop reflect);
896 static void set_modifiers(oop reflect, int value);
897
898 static oop executable(oop constructor);
899 static void set_executable(oop constructor, oop value);
900
901 friend class JavaClasses;
902 };
903
904 #define MODULE_INJECTED_FIELDS(macro) \
905 macro(java_lang_Module, module_entry, intptr_signature, false)
906
907 class java_lang_Module {
908 private:
909 static int _loader_offset;
910 static int _name_offset;
911 static int _module_entry_offset;
912
913 static void compute_offsets();
914
915 public:
916 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
917
918 // Allocation
919 static Handle create(Handle loader, Handle module_name, TRAPS);
920
921 // Testers
922 static bool is_instance(oop obj);
923
924 // Accessors
925 static oop loader(oop module);
926 static void set_loader(oop module, oop value);
927
928 // CDS
929 static int module_entry_offset() { return _module_entry_offset; }
930
931 static oop name(oop module);
932 static void set_name(oop module, oop value);
933
934 static ModuleEntry* module_entry(oop module);
935 static ModuleEntry* module_entry_raw(oop module);
936 static void set_module_entry(oop module, ModuleEntry* module_entry);
937
938 friend class JavaClasses;
939 };
940
941 #define CONSTANTPOOL_INJECTED_FIELDS(macro) \
942 macro(reflect_ConstantPool, vmholder, object_signature, false)
943
944 // Interface to jdk.internal.reflect.ConstantPool objects
945 class reflect_ConstantPool {
946 private:
947 // Note that to reduce dependencies on the JDK we compute these
948 // offsets at run-time. This field is the oop offset for the
949 // actual constant pool, previously called constantPoolOop.
950 static int _vmholder_offset;
951
952 static void compute_offsets();
953
954 public:
955 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
956
957 // Allocation
958 static Handle create(TRAPS);
959
960 // Accessors
961 static void set_cp(oop reflect, ConstantPool* value);
962
963 static ConstantPool* get_cp(oop reflect);
964
965 // Debugging
966 friend class JavaClasses;
967 };
968
969
970 // Interface to java.lang primitive type boxing objects:
971 // - java.lang.Boolean
972 // - java.lang.Character
973 // - java.lang.Float
974 // - java.lang.Double
975 // - java.lang.Byte
976 // - java.lang.Short
977 // - java.lang.Integer
978 // - java.lang.Long
979
980 // This could be separated out into 8 individual classes.
981
982 class java_lang_boxing_object: AllStatic {
983 private:
984 static int _value_offset;
985 static int _long_value_offset;
986
987 static void compute_offsets();
988 static oop initialize_and_allocate(BasicType type, TRAPS);
989 public:
990 // Allocation. Returns a boxed value, or null for invalid type.
991 static oop create(BasicType type, jvalue* value, TRAPS);
992 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
993 static BasicType get_value(oop box, jvalue* value);
994 static BasicType set_value(oop box, jvalue* value);
995 static BasicType basic_type(oop box);
996 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
997 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
998 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
999 static void print(BasicType type, jvalue* value, outputStream* st);
1000
1001 static int value_offset(BasicType type) {
1002 return is_double_word_type(type) ? _long_value_offset : _value_offset;
1003 }
1004
1005 static void serialize_offsets(SerializeClosure* f);
1006
1007 // Debugging
1008 friend class JavaClasses;
1009 };
1010
1011
1012
1013 // Interface to java.lang.ref.Reference objects
1014
1015 class java_lang_ref_Reference: AllStatic {
1016 static int _referent_offset;
1017 static int _queue_offset;
1018 static int _next_offset;
1019 static int _discovered_offset;
1020
1021 static bool _offsets_initialized;
1022
1023 public:
1024 // Accessors
1025 static inline oop weak_referent_no_keepalive(oop ref);
1026 static inline oop weak_referent(oop ref);
1027 static inline oop phantom_referent_no_keepalive(oop ref);
1028 static inline oop unknown_referent_no_keepalive(oop ref);
1029 static inline void clear_referent(oop ref);
1030 static inline void clear_referent_raw(oop ref);
1031 static inline HeapWord* referent_addr_raw(oop ref);
1032 static inline oop next(oop ref);
1033 static inline void set_next(oop ref, oop value);
1034 static inline void set_next_raw(oop ref, oop value);
1035 static inline HeapWord* next_addr_raw(oop ref);
1036 static inline oop discovered(oop ref);
1037 static inline void set_discovered(oop ref, oop value);
1038 static inline void set_discovered_raw(oop ref, oop value);
1039 static inline HeapWord* discovered_addr_raw(oop ref);
1040 static bool is_referent_field(oop obj, ptrdiff_t offset);
1041 static inline bool is_final(oop ref);
1042 static inline bool is_phantom(oop ref);
1043 static inline bool is_weak(oop ref);
1044 static inline bool is_soft(oop ref);
1045
1046 static int referent_offset() { CHECK_INIT(_referent_offset); }
1047 static int queue_offset() { CHECK_INIT(_queue_offset); }
1048 static int next_offset() { CHECK_INIT(_next_offset); }
1049 static int discovered_offset() { CHECK_INIT(_discovered_offset); }
1050
1051 static void compute_offsets();
1052 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1053 };
1054
1055
1056 // Interface to java.lang.ref.SoftReference objects
1057
1058 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
1059 static int _timestamp_offset;
1060 static int _static_clock_offset;
1061
1062 public:
1063 // Accessors
1064 static jlong timestamp(oop ref);
1065
1066 // Accessors for statics
1067 static jlong clock();
1068 static void set_clock(jlong value);
1069
1070 static void compute_offsets();
1071 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1072 };
1073
1074 // Interface to java.lang.invoke.MethodHandle objects
1075
1076 class java_lang_invoke_MethodHandle: AllStatic {
1077 friend class JavaClasses;
1078
1079 private:
1080 static int _type_offset; // the MethodType of this MH
1081 static int _form_offset; // the LambdaForm of this MH
1082
1083 static void compute_offsets();
1084
1085 public:
1086 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1087
1088 // Accessors
1089 static oop type(oop mh);
1090 static void set_type(oop mh, oop mtype);
1091
1092 static oop form(oop mh);
1093 static void set_form(oop mh, oop lform);
1094
1095 // Testers
1096 static bool is_subclass(Klass* klass) {
1097 return klass->is_subclass_of(vmClasses::MethodHandle_klass());
1098 }
1099 static bool is_instance(oop obj);
1100
1101 // Accessors for code generation:
1102 static int type_offset() { CHECK_INIT(_type_offset); }
1103 static int form_offset() { CHECK_INIT(_form_offset); }
1104 };
1105
1106 // Interface to java.lang.invoke.DirectMethodHandle objects
1107
1108 class java_lang_invoke_DirectMethodHandle: AllStatic {
1109 friend class JavaClasses;
1110
1111 private:
1112 static int _member_offset; // the MemberName of this DMH
1113
1114 static void compute_offsets();
1115
1116 public:
1117 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1118
1119 // Accessors
1120 static oop member(oop mh);
1121
1122 // Testers
1123 static bool is_subclass(Klass* klass) {
1124 return klass->is_subclass_of(vmClasses::DirectMethodHandle_klass());
1125 }
1126 static bool is_instance(oop obj);
1127
1128 // Accessors for code generation:
1129 static int member_offset() { CHECK_INIT(_member_offset); }
1130 };
1131
1132 // Interface to java.lang.invoke.LambdaForm objects
1133 // (These are a private interface for managing adapter code generation.)
1134
1135 class java_lang_invoke_LambdaForm: AllStatic {
1136 friend class JavaClasses;
1137
1138 private:
1139 static int _vmentry_offset; // type is MemberName
1140
1141 static void compute_offsets();
1142
1143 public:
1144 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1145
1146 // Accessors
1147 static oop vmentry(oop lform);
1148
1149 // Testers
1150 static bool is_subclass(Klass* klass) {
1151 return vmClasses::LambdaForm_klass() != nullptr &&
1152 klass->is_subclass_of(vmClasses::LambdaForm_klass());
1153 }
1154 static bool is_instance(oop obj);
1155
1156 // Accessors for code generation:
1157 static int vmentry_offset() { CHECK_INIT(_vmentry_offset); }
1158 };
1159
1160 // Interface to java.lang.invoke.NativeEntryPoint objects
1161 // (These are a private interface for managing adapter code generation.)
1162
1163 class jdk_internal_foreign_abi_NativeEntryPoint: AllStatic {
1164 friend class JavaClasses;
1165
1166 private:
1167 static int _method_type_offset;
1168 static int _downcall_stub_address_offset;
1169
1170 static void compute_offsets();
1171
1172 public:
1173 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1174
1175 // Accessors
1176 static oop method_type(oop entry);
1177 static jlong downcall_stub_address(oop entry);
1178
1179 // Accessors for code generation:
1180 static int method_type_offset_in_bytes() { return _method_type_offset; }
1181 static int downcall_stub_address_offset_in_bytes() { return _downcall_stub_address_offset; }
1182 };
1183
1184 class jdk_internal_foreign_abi_ABIDescriptor: AllStatic {
1185 friend class JavaClasses;
1186
1187 private:
1188 static int _inputStorage_offset;
1189 static int _outputStorage_offset;
1190 static int _volatileStorage_offset;
1191 static int _stackAlignment_offset;
1192 static int _shadowSpace_offset;
1193 static int _scratch1_offset;
1194 static int _scratch2_offset;
1195
1196 static void compute_offsets();
1197
1198 public:
1199 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1200
1201 // Accessors
1202 static objArrayOop inputStorage(oop entry);
1203 static objArrayOop outputStorage(oop entry);
1204 static objArrayOop volatileStorage(oop entry);
1205 static jint stackAlignment(oop entry);
1206 static jint shadowSpace(oop entry);
1207 static oop scratch1(oop entry);
1208 static oop scratch2(oop entry);
1209 };
1210
1211 class jdk_internal_foreign_abi_VMStorage: AllStatic {
1212 friend class JavaClasses;
1213
1214 private:
1215 static int _type_offset;
1216 static int _indexOrOffset_offset;
1217 static int _segmentMaskOrSize_offset;
1218 static int _debugName_offset;
1219
1220 static void compute_offsets();
1221
1222 public:
1223 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1224
1225 // Accessors
1226 static jbyte type(oop entry);
1227 static jint index_or_offset(oop entry);
1228 static jshort segment_mask_or_size(oop entry);
1229 static oop debugName(oop entry);
1230
1231 // Testers
1232 static bool is_subclass(Klass* klass) {
1233 return vmClasses::VMStorage_klass() != nullptr &&
1234 klass->is_subclass_of(vmClasses::VMStorage_klass());
1235 }
1236 static bool is_instance(oop obj);
1237 };
1238
1239 class jdk_internal_foreign_abi_CallConv: AllStatic {
1240 friend class JavaClasses;
1241
1242 private:
1243 static int _argRegs_offset;
1244 static int _retRegs_offset;
1245
1246 static void compute_offsets();
1247
1248 public:
1249 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1250
1251 // Accessors
1252 static objArrayOop argRegs(oop entry);
1253 static objArrayOop retRegs(oop entry);
1254
1255 // Testers
1256 static bool is_subclass(Klass* klass) {
1257 return vmClasses::CallConv_klass() != nullptr &&
1258 klass->is_subclass_of(vmClasses::CallConv_klass());
1259 }
1260 static bool is_instance(oop obj);
1261 };
1262
1263 // Interface to java.lang.invoke.MemberName objects
1264 // (These are a private interface for Java code to query the class hierarchy.)
1265
1266 #define RESOLVEDMETHOD_INJECTED_FIELDS(macro) \
1267 macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false)
1268
1269 class java_lang_invoke_ResolvedMethodName : AllStatic {
1270 friend class JavaClasses;
1271
1272 static int _vmtarget_offset;
1273 static int _vmholder_offset;
1274
1275 static void compute_offsets();
1276 public:
1277 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1278
1279 static int vmtarget_offset() { CHECK_INIT(_vmtarget_offset); }
1280
1281 static Method* vmtarget(oop resolved_method);
1282 static void set_vmtarget(oop resolved_method, Method* method);
1283
1284 static void set_vmholder(oop resolved_method, oop holder);
1285
1286 // find or create resolved member name
1287 static oop find_resolved_method(const methodHandle& m, TRAPS);
1288
1289 static bool is_instance(oop resolved_method);
1290 };
1291
1292
1293 #define MEMBERNAME_INJECTED_FIELDS(macro) \
1294 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false)
1295
1296
1297 class java_lang_invoke_MemberName: AllStatic {
1298 friend class JavaClasses;
1299
1300 private:
1301 // From java.lang.invoke.MemberName:
1302 // private Class<?> clazz; // class in which the method is defined
1303 // private String name; // may be null if not yet materialized
1304 // private Object type; // may be null if not yet materialized
1305 // private int flags; // modifier bits; see reflect.Modifier
1306 // private ResolvedMethodName method; // holds VM-specific target value
1307 // private intptr_t vmindex; // member index within class or interface
1308 static int _clazz_offset;
1309 static int _name_offset;
1310 static int _type_offset;
1311 static int _flags_offset;
1312 static int _method_offset;
1313 static int _vmindex_offset;
1314
1315 static void compute_offsets();
1316
1317 public:
1318 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1319 // Accessors
1320 static oop clazz(oop mname);
1321 static void set_clazz(oop mname, oop clazz);
1322
1323 static oop type(oop mname);
1324 static void set_type(oop mname, oop type);
1325
1326 static oop name(oop mname);
1327 static void set_name(oop mname, oop name);
1328
1329 static int flags(oop mname);
1330 static void set_flags(oop mname, int flags);
1331
1332 // Link through ResolvedMethodName field to get Method*
1333 static Method* vmtarget(oop mname);
1334 static void set_method(oop mname, oop method);
1335
1336 static intptr_t vmindex(oop mname);
1337 static void set_vmindex(oop mname, intptr_t index);
1338
1339 // Testers
1340 static bool is_subclass(Klass* klass) {
1341 return klass->is_subclass_of(vmClasses::MemberName_klass());
1342 }
1343 static bool is_instance(oop obj);
1344
1345 static bool is_method(oop obj);
1346
1347 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1348 enum {
1349 MN_IS_METHOD = 0x00010000, // method (not constructor)
1350 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
1351 MN_IS_FIELD = 0x00040000, // field
1352 MN_IS_TYPE = 0x00080000, // nested type
1353 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected
1354 MN_TRUSTED_FINAL = 0x00200000, // trusted final field
1355 MN_HIDDEN_MEMBER = 0x00400000, // @Hidden annotation detected
1356 MN_REFERENCE_KIND_SHIFT = 24, // refKind
1357 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1358 MN_NESTMATE_CLASS = 0x00000001,
1359 MN_HIDDEN_CLASS = 0x00000002,
1360 MN_STRONG_LOADER_LINK = 0x00000004,
1361 MN_ACCESS_VM_ANNOTATIONS = 0x00000008,
1362 // Lookup modes
1363 MN_MODULE_MODE = 0x00000010,
1364 MN_UNCONDITIONAL_MODE = 0x00000020,
1365 MN_TRUSTED_MODE = -1
1366 };
1367
1368 // Accessors for code generation:
1369 static int clazz_offset() { CHECK_INIT(_clazz_offset); }
1370 static int type_offset() { CHECK_INIT(_type_offset); }
1371 static int flags_offset() { CHECK_INIT(_flags_offset); }
1372 static int method_offset() { CHECK_INIT(_method_offset); }
1373 static int vmindex_offset() { CHECK_INIT(_vmindex_offset); }
1374 };
1375
1376
1377 // Interface to java.lang.invoke.MethodType objects
1378
1379 class java_lang_invoke_MethodType: AllStatic {
1380 friend class JavaClasses;
1381
1382 private:
1383 static int _rtype_offset;
1384 static int _ptypes_offset;
1385
1386 static void compute_offsets();
1387
1388 public:
1389 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1390 // Accessors
1391 static oop rtype(oop mt);
1392 static objArrayOop ptypes(oop mt);
1393
1394 static oop ptype(oop mt, int index);
1395 static int ptype_count(oop mt);
1396
1397 static int ptype_slot_count(oop mt); // extra counts for long/double
1398 static int rtype_slot_count(oop mt); // extra counts for long/double
1399
1400 static Symbol* as_signature(oop mt, bool intern_if_not_found);
1401 static void print_signature(oop mt, outputStream* st);
1402
1403 static bool is_instance(oop obj);
1404
1405 static bool equals(oop mt1, oop mt2);
1406
1407 // Accessors for code generation:
1408 static int rtype_offset() { CHECK_INIT(_rtype_offset); }
1409 static int ptypes_offset() { CHECK_INIT(_ptypes_offset); }
1410 };
1411
1412
1413 // Interface to java.lang.invoke.CallSite objects
1414 #define CALLSITE_INJECTED_FIELDS(macro) \
1415 macro(java_lang_invoke_CallSite, vmdependencies, intptr_signature, false) \
1416 macro(java_lang_invoke_CallSite, last_cleanup, long_signature, false)
1417
1418 class java_lang_invoke_CallSite: AllStatic {
1419 friend class JavaClasses;
1420
1421 private:
1422 static int _target_offset;
1423 static int _vmdependencies_offset;
1424 static int _last_cleanup_offset;
1425
1426 static void compute_offsets();
1427
1428 public:
1429 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1430 // Accessors
1431 static oop target( oop site);
1432 static void set_target( oop site, oop target);
1433 static void set_target_volatile( oop site, oop target);
1434
1435 static DependencyContext vmdependencies(oop call_site);
1436
1437 // Testers
1438 static bool is_subclass(Klass* klass) {
1439 return klass->is_subclass_of(vmClasses::CallSite_klass());
1440 }
1441 static bool is_instance(oop obj);
1442
1443 // Accessors for code generation:
1444 static int target_offset() { CHECK_INIT(_target_offset); }
1445 };
1446
1447 // Interface to java.lang.invoke.ConstantCallSite objects
1448
1449 class java_lang_invoke_ConstantCallSite: AllStatic {
1450 friend class JavaClasses;
1451
1452 private:
1453 static int _is_frozen_offset;
1454
1455 static void compute_offsets();
1456
1457 public:
1458 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1459 // Accessors
1460 static jboolean is_frozen(oop site);
1461
1462 // Testers
1463 static bool is_subclass(Klass* klass) {
1464 return klass->is_subclass_of(vmClasses::ConstantCallSite_klass());
1465 }
1466 static bool is_instance(oop obj);
1467 };
1468
1469 // Interface to java.lang.ClassLoader objects
1470
1471 #define CLASSLOADER_INJECTED_FIELDS(macro) \
1472 macro(java_lang_ClassLoader, loader_data, intptr_signature, false)
1473
1474 class java_lang_ClassLoader : AllStatic {
1475 private:
1476 static int _loader_data_offset;
1477 static int _parent_offset;
1478 static int _parallelCapable_offset;
1479 static int _name_offset;
1480 static int _nameAndId_offset;
1481 static int _unnamedModule_offset;
1482
1483 static void compute_offsets();
1484
1485 public:
1486 // Support for CDS
1487 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1488 static int loader_data_offset() { return _loader_data_offset; }
1489
1490 static ClassLoaderData* loader_data_acquire(oop loader);
1491 static ClassLoaderData* loader_data(oop loader);
1492 static void release_set_loader_data(oop loader, ClassLoaderData* new_data);
1493
1494 static oop parent(oop loader);
1495 static oop parent_no_keepalive(oop loader);
1496 static oop name(oop loader);
1497 static oop nameAndId(oop loader);
1498 static bool isAncestor(oop loader, oop cl);
1499
1500 // Support for parallelCapable field
1501 static bool parallelCapable(oop the_class_mirror);
1502
1503 static bool is_trusted_loader(oop loader);
1504
1505 // Testers
1506 static bool is_subclass(Klass* klass) {
1507 return klass->is_subclass_of(vmClasses::ClassLoader_klass());
1508 }
1509 static bool is_instance(oop obj);
1510
1511 static oop unnamedModule(oop loader);
1512
1513 // Debugging
1514 friend class JavaClasses;
1515 };
1516
1517
1518 // Interface to java.lang.System objects
1519
1520 class java_lang_System : AllStatic {
1521 private:
1522 static int _static_in_offset;
1523 static int _static_out_offset;
1524 static int _static_err_offset;
1525
1526 public:
1527 static int in_offset() { CHECK_INIT(_static_in_offset); }
1528 static int out_offset() { CHECK_INIT(_static_out_offset); }
1529 static int err_offset() { CHECK_INIT(_static_err_offset); }
1530
1531 static void compute_offsets();
1532 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1533
1534 // Debugging
1535 friend class JavaClasses;
1536 };
1537
1538
1539 // Interface to java.lang.StackTraceElement objects
1540
1541 class java_lang_StackTraceElement: AllStatic {
1542 private:
1543 static int _declaringClassObject_offset;
1544 static int _classLoaderName_offset;
1545 static int _moduleName_offset;
1546 static int _moduleVersion_offset;
1547 static int _declaringClass_offset;
1548 static int _methodName_offset;
1549 static int _fileName_offset;
1550 static int _lineNumber_offset;
1551
1552 // Setters
1553 static void set_classLoaderName(oop element, oop value);
1554 static void set_moduleName(oop element, oop value);
1555 static void set_moduleVersion(oop element, oop value);
1556 static void set_declaringClass(oop element, oop value);
1557 static void set_methodName(oop element, oop value);
1558 static void set_fileName(oop element, oop value);
1559 static void set_lineNumber(oop element, int value);
1560 static void set_declaringClassObject(oop element, oop value);
1561
1562 static void decode_file_and_line(Handle java_mirror, InstanceKlass* holder, int version,
1563 const methodHandle& method, int bci,
1564 Symbol*& source, oop& source_file, int& line_number, TRAPS);
1565
1566 public:
1567 // Create an instance of StackTraceElement
1568 static oop create(const methodHandle& method, int bci, TRAPS);
1569
1570 static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1571 int version, int bci, Symbol* name, TRAPS);
1572
1573 static void compute_offsets();
1574 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1575
1576 #if INCLUDE_JVMCI
1577 static void decode(const methodHandle& method, int bci, Symbol*& fileName, int& lineNumber, TRAPS);
1578 #endif
1579
1580 // Debugging
1581 friend class JavaClasses;
1582 };
1583
1584
1585 class Backtrace: AllStatic {
1586 public:
1587 // Helper backtrace functions to store bci|version together.
1588 static int merge_bci_and_version(int bci, int version);
1589 static int merge_mid_and_cpref(int mid, int cpref);
1590 static int bci_at(unsigned int merged);
1591 static int version_at(unsigned int merged);
1592 static int mid_at(unsigned int merged);
1593 static int cpref_at(unsigned int merged);
1594 static int get_line_number(Method* method, int bci);
1595 static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1596
1597 // Debugging
1598 friend class JavaClasses;
1599 };
1600
1601 class java_lang_ClassFrameInfo: AllStatic {
1602 private:
1603 static int _classOrMemberName_offset;
1604 static int _flags_offset;
1605
1606 public:
1607 static oop classOrMemberName(oop info);
1608 static int flags(oop info);
1609
1610 // Setters
1611 static void init_class(Handle stackFrame, const methodHandle& m);
1612 static void init_method(Handle stackFrame, const methodHandle& m, TRAPS);
1613
1614 static void compute_offsets();
1615 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1616
1617 // Debugging
1618 friend class JavaClasses;
1619 };
1620
1621 // Interface to java.lang.StackFrameInfo objects
1622
1623 #define STACKFRAMEINFO_INJECTED_FIELDS(macro) \
1624 macro(java_lang_StackFrameInfo, version, short_signature, false)
1625
1626 class java_lang_StackFrameInfo: AllStatic {
1627 private:
1628 static int _type_offset;
1629 static int _name_offset;
1630 static int _bci_offset;
1631 static int _version_offset;
1632 static int _contScope_offset;
1633
1634 public:
1635 // Getters
1636 static oop name(oop info);
1637 static oop type(oop info);
1638 static Method* get_method(oop info);
1639
1640 // Setters
1641 static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, oop cont, TRAPS);
1642 static void set_name(oop info, oop value);
1643 static void set_type(oop info, oop value);
1644 static void set_bci(oop info, int value);
1645
1646 static void set_version(oop info, short value);
1647 static void set_contScope(oop info, oop value);
1648
1649 static void compute_offsets();
1650 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1651
1652 static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS);
1653
1654 // Debugging
1655 friend class JavaClasses;
1656 };
1657
1658 class java_lang_LiveStackFrameInfo: AllStatic {
1659 private:
1660 static int _monitors_offset;
1661 static int _locals_offset;
1662 static int _operands_offset;
1663 static int _mode_offset;
1664
1665 public:
1666 static void set_monitors(oop info, oop value);
1667 static void set_locals(oop info, oop value);
1668 static void set_operands(oop info, oop value);
1669 static void set_mode(oop info, int value);
1670
1671 static void compute_offsets();
1672 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1673
1674 // Debugging
1675 friend class JavaClasses;
1676 };
1677
1678 // Interface to java.lang.reflect.RecordComponent objects
1679
1680 class java_lang_reflect_RecordComponent: AllStatic {
1681 private:
1682 static int _clazz_offset;
1683 static int _name_offset;
1684 static int _type_offset;
1685 static int _accessor_offset;
1686 static int _signature_offset;
1687 static int _annotations_offset;
1688 static int _typeAnnotations_offset;
1689
1690 // Setters
1691 static void set_clazz(oop element, oop value);
1692 static void set_name(oop element, oop value);
1693 static void set_type(oop element, oop value);
1694 static void set_accessor(oop element, oop value);
1695 static void set_signature(oop element, oop value);
1696 static void set_annotations(oop element, oop value);
1697 static void set_typeAnnotations(oop element, oop value);
1698
1699 public:
1700 // Create an instance of RecordComponent
1701 static oop create(InstanceKlass* holder, RecordComponent* component, TRAPS);
1702
1703 static void compute_offsets();
1704 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1705
1706 // Debugging
1707 friend class JavaClasses;
1708 };
1709
1710
1711 // Interface to java.lang.AssertionStatusDirectives objects
1712
1713 class java_lang_AssertionStatusDirectives: AllStatic {
1714 private:
1715 static int _classes_offset;
1716 static int _classEnabled_offset;
1717 static int _packages_offset;
1718 static int _packageEnabled_offset;
1719 static int _deflt_offset;
1720
1721 public:
1722 // Setters
1723 static void set_classes(oop obj, oop val);
1724 static void set_classEnabled(oop obj, oop val);
1725 static void set_packages(oop obj, oop val);
1726 static void set_packageEnabled(oop obj, oop val);
1727 static void set_deflt(oop obj, bool val);
1728
1729 static void compute_offsets();
1730 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1731
1732 // Debugging
1733 friend class JavaClasses;
1734 };
1735
1736
1737 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1738 private:
1739 static int _owner_offset;
1740 public:
1741 static void compute_offsets();
1742 static oop get_owner_threadObj(oop obj);
1743 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1744 };
1745
1746 // Interface to jdk.internal.misc.UnsafeConsants
1747
1748 class jdk_internal_misc_UnsafeConstants : AllStatic {
1749 public:
1750 static void set_unsafe_constants();
1751 static void compute_offsets() { }
1752 static void serialize_offsets(SerializeClosure* f) { }
1753 };
1754
1755 // Interface to jdk.internal.vm.vector.VectorSupport.VectorPayload objects
1756
1757 class vector_VectorPayload : AllStatic {
1758 private:
1759 static int _payload_offset;
1760 public:
1761 static void set_payload(oop o, oop val);
1762
1763 static void compute_offsets();
1764 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1765
1766 // Testers
1767 static bool is_subclass(Klass* klass) {
1768 return klass->is_subclass_of(vmClasses::vector_VectorPayload_klass());
1769 }
1770 static bool is_instance(oop obj);
1771 };
1772
1773 class java_lang_Integer : AllStatic {
1774 public:
1775 static jint value(oop obj);
1776 };
1777
1778 class java_lang_Long : AllStatic {
1779 public:
1780 static jlong value(oop obj);
1781 };
1782
1783 class java_lang_Character : AllStatic {
1784 public:
1785 static jchar value(oop obj);
1786 };
1787
1788 class java_lang_Short : AllStatic {
1789 public:
1790 static jshort value(oop obj);
1791 };
1792
1793 class java_lang_Byte : AllStatic {
1794 public:
1795 static jbyte value(oop obj);
1796 };
1797
1798 class java_lang_Boolean : AllStatic {
1799 private:
1800 static int _static_TRUE_offset;
1801 static int _static_FALSE_offset;
1802 public:
1803 static Symbol* symbol();
1804 static void compute_offsets(InstanceKlass* k);
1805 static oop get_TRUE(InstanceKlass *k);
1806 static oop get_FALSE(InstanceKlass *k);
1807 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1808 static jboolean value(oop obj);
1809 };
1810
1811 class java_lang_Integer_IntegerCache : AllStatic {
1812 private:
1813 static int _static_cache_offset;
1814 public:
1815 static Symbol* symbol();
1816 static void compute_offsets(InstanceKlass* k);
1817 static objArrayOop cache(InstanceKlass *k);
1818 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1819 };
1820
1821 class java_lang_Long_LongCache : AllStatic {
1822 private:
1823 static int _static_cache_offset;
1824 public:
1825 static Symbol* symbol();
1826 static void compute_offsets(InstanceKlass* k);
1827 static objArrayOop cache(InstanceKlass *k);
1828 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1829 };
1830
1831 class java_lang_Character_CharacterCache : AllStatic {
1832 private:
1833 static int _static_cache_offset;
1834 public:
1835 static Symbol* symbol();
1836 static void compute_offsets(InstanceKlass* k);
1837 static objArrayOop cache(InstanceKlass *k);
1838 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1839 };
1840
1841 class java_lang_Short_ShortCache : AllStatic {
1842 private:
1843 static int _static_cache_offset;
1844 public:
1845 static Symbol* symbol();
1846 static void compute_offsets(InstanceKlass* k);
1847 static objArrayOop cache(InstanceKlass *k);
1848 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1849 };
1850
1851 class java_lang_Byte_ByteCache : AllStatic {
1852 private:
1853 static int _static_cache_offset;
1854 public:
1855 static Symbol* symbol();
1856 static void compute_offsets(InstanceKlass* k);
1857 static objArrayOop cache(InstanceKlass *k);
1858 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1859 };
1860
1861
1862 // Interface to java.lang.InternalError objects
1863
1864 #define INTERNALERROR_INJECTED_FIELDS(macro) \
1865 macro(java_lang_InternalError, during_unsafe_access, bool_signature, false)
1866
1867 class java_lang_InternalError : AllStatic {
1868 private:
1869 static int _during_unsafe_access_offset;
1870 public:
1871 static jboolean during_unsafe_access(oop internal_error);
1872 static void set_during_unsafe_access(oop internal_error);
1873 static void compute_offsets();
1874 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1875 };
1876
1877 // Use to declare fields that need to be injected into Java classes
1878 // for the JVM to use. The name_index and signature_index are
1879 // declared in vmSymbols. The may_be_java flag is used to declare
1880 // fields that might already exist in Java but should be injected if
1881 // they don't. Otherwise the field is unconditionally injected and
1882 // the JVM uses the injected one. This is to ensure that name
1883 // collisions don't occur. In general may_be_java should be false
1884 // unless there's a good reason.
1885
1886 class InjectedField {
1887 public:
1888 const vmClassID klass_id;
1889 const vmSymbolID name_index;
1890 const vmSymbolID signature_index;
1891 const bool may_be_java;
1892
1893
1894 InstanceKlass* klass() const { return vmClasses::klass_at(klass_id); }
1895 Symbol* name() const { return lookup_symbol(name_index); }
1896 Symbol* signature() const { return lookup_symbol(signature_index); }
1897
1898 int compute_offset();
1899
1900 // Find the Symbol for this index
1901 static Symbol* lookup_symbol(vmSymbolID symbol_index) {
1902 return Symbol::vm_symbol_at(symbol_index);
1903 }
1904 };
1905
1906
1907 // Interface to hard-coded offset checking
1908
1909 enum class InjectedFieldID : int;
1910
1911 class JavaClasses : AllStatic {
1912 private:
1913
1914 static InjectedField _injected_fields[];
1915
1916 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1917 public:
1918
1919 static int compute_injected_offset(InjectedFieldID id);
1920
1921 static void compute_offsets();
1922 static void check_offsets() PRODUCT_RETURN;
1923 static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN;
1924 static InjectedField* get_injected(Symbol* class_name, int* field_count);
1925 static bool is_supported_for_archiving(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(false);
1926
1927 static void compute_offset(int &dest_offset,
1928 InstanceKlass* ik, Symbol* name_symbol, Symbol* signature_symbol,
1929 bool is_static = false);
1930 static void compute_offset(int& dest_offset, InstanceKlass* ik,
1931 const char* name_string, Symbol* signature_symbol,
1932 bool is_static = false);
1933 };
1934
1935 #undef CHECK_INIT
1936
1937 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP