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