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