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