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 _recheckInterval_offset;
570 static int _timeout_offset;
571 static int _objectWaiter_offset;
572 JFR_ONLY(static int _jfr_epoch_offset;)
573 public:
574 enum {
575 NEW = 0,
576 STARTED = 1,
577 RUNNING = 2,
578 PARKING = 3,
579 PARKED = 4,
580 PINNED = 5,
581 TIMED_PARKING = 6,
582 TIMED_PARKED = 7,
583 TIMED_PINNED = 8,
584 UNPARKED = 9,
585 YIELDING = 10,
586 YIELDED = 11,
587 BLOCKING = 12,
588 BLOCKED = 13,
589 UNBLOCKED = 14,
590 WAITING = 15,
591 WAIT = 16, // waiting in Object.wait
592 TIMED_WAITING = 17,
593 TIMED_WAIT = 18, // waiting in timed-Object.wait
594 TERMINATED = 99,
595
596 // additional state bits
597 SUSPENDED = 1 << 8, // suspended when unmounted
598 };
599
600 static void compute_offsets();
601 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
602
603 // Testers
604 static bool is_subclass(Klass* klass) {
605 return klass->is_subclass_of(vmClasses::VirtualThread_klass());
606 }
607 static bool is_instance(oop obj);
608
609 static oop vthread_scope();
610 static oop carrier_thread(oop vthread);
611 static oop continuation(oop vthread);
612 static int state(oop vthread);
613 static void set_state(oop vthread, int state);
614 static int cmpxchg_state(oop vthread, int old_state, int new_state);
615 static oop next(oop vthread);
616 static void set_next(oop vthread, oop next_vthread);
617 static bool set_onWaitingList(oop vthread, OopHandle& list_head);
618 static jlong timeout(oop vthread);
619 static void set_timeout(oop vthread, jlong value);
620 static void set_notified(oop vthread, jboolean value);
621 static bool is_preempted(oop vthread);
622 static JavaThreadStatus map_state_to_thread_status(int state);
623
624 static inline ObjectWaiter* objectWaiter(oop vthread);
625 static inline void set_objectWaiter(oop vthread, ObjectWaiter* waiter);
626 static ObjectMonitor* current_pending_monitor(oop vthread);
627 static ObjectMonitor* current_waiting_monitor(oop vthread);
628 };
629
630
631 // Interface to java.lang.Throwable objects
632
633 class java_lang_Throwable: AllStatic {
634 friend class BacktraceBuilder;
635 friend class BacktraceIterator;
636
637 private:
638 // Trace constants
639 enum {
640 trace_methods_offset = 0,
641 trace_bcis_offset = 1,
642 trace_mirrors_offset = 2,
643 trace_names_offset = 3,
644 trace_conts_offset = 4,
645 trace_next_offset = 5,
646 trace_hidden_offset = 6,
647 trace_size = 7,
648 trace_chunk_size = 32
649 };
650
651 static int _backtrace_offset;
652 static int _detailMessage_offset;
653 static int _stackTrace_offset;
654 static int _depth_offset;
655 static int _cause_offset;
656 static int _static_unassigned_stacktrace_offset;
657
658 // StackTrace (programmatic access, new since 1.4)
659 static void clear_stacktrace(oop throwable);
660 // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
661 static void set_stacktrace(oop throwable, oop st_element_array);
662 static oop unassigned_stacktrace();
663
664 public:
665 // Backtrace
666 static oop backtrace(oop throwable);
667 static void set_backtrace(oop throwable, oop value);
668 static int depth(oop throwable);
669 static void set_depth(oop throwable, int value);
670 // Message
671 static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); }
672 static oop message(oop throwable);
673 static const char* message_as_utf8(oop throwable);
674 static void set_message(oop throwable, oop value);
675
676 static oop cause(oop throwable);
677
678 static void print_stack_element(outputStream *st, Method* method, int bci);
679
680 static void compute_offsets();
681 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
682
683 // Allocate space for backtrace (created but stack trace not filled in)
684 static void allocate_backtrace(Handle throwable, TRAPS);
685 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
686 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
687 // Fill in current stack trace, can cause GC
688 static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
689 static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
690
691 // Programmatic access to stack trace
692 static void get_stack_trace_elements(int depth, Handle backtrace, objArrayHandle stack_trace, TRAPS);
693
694 // For recreating class initialization error exceptions.
695 static Handle create_initialization_error(JavaThread* current, Handle throwable);
696
697 static oop create_exception_instance(Symbol* class_name, TRAPS);
698
699 // Printing
700 static void print(oop throwable, outputStream* st);
701 static void print_stack_trace(Handle throwable, outputStream* st);
702 static void java_printStackTrace(Handle throwable, TRAPS);
703 // Debugging
704 friend class JavaClasses;
705 // Gets the method and bci of the top frame (TOS). Returns false if this failed.
706 static bool get_top_method_and_bci(oop throwable, Method** method, int* bci);
707 };
708
709
710 // Interface to java.lang.reflect.AccessibleObject objects
711
712 class java_lang_reflect_AccessibleObject: AllStatic {
713 private:
714 // Note that to reduce dependencies on the JDK we compute these
715 // offsets at run-time.
716 static int _override_offset;
717
718 static void compute_offsets();
719
720 public:
721 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
722
723 // Accessors
724 static jboolean override(oop reflect);
725 static void set_override(oop reflect, jboolean value);
726
727 // Debugging
728 friend class JavaClasses;
729 };
730
731
732 // Interface to java.lang.reflect.Method objects
733
734 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
735 private:
736 // Note that to reduce dependencies on the JDK we compute these
737 // offsets at run-time.
738 static int _clazz_offset;
739 static int _name_offset;
740 static int _returnType_offset;
741 static int _parameterTypes_offset;
742 static int _exceptionTypes_offset;
743 static int _slot_offset;
744 static int _modifiers_offset;
745 static int _signature_offset;
746 static int _annotations_offset;
747 static int _parameter_annotations_offset;
748 static int _annotation_default_offset;
749
750 static void compute_offsets();
751 public:
752 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
753
754 // Allocation
755 static Handle create(TRAPS);
756
757 // Accessors
758 static oop clazz(oop reflect);
759 static void set_clazz(oop reflect, oop value);
760
761 static void set_name(oop method, oop value);
762
763 static oop return_type(oop method);
764 static void set_return_type(oop method, oop value);
765
766 static oop parameter_types(oop method);
767 static void set_parameter_types(oop method, oop value);
768
769 static int slot(oop reflect);
770 static void set_slot(oop reflect, int value);
771
772 static void set_exception_types(oop method, oop value);
773 static void set_modifiers(oop method, int value);
774 static void set_signature(oop method, oop value);
775 static void set_annotations(oop method, oop value);
776 static void set_parameter_annotations(oop method, oop value);
777 static void set_annotation_default(oop method, oop value);
778
779 // Debugging
780 friend class JavaClasses;
781 };
782
783
784 // Interface to java.lang.reflect.Constructor objects
785
786 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
787 private:
788 // Note that to reduce dependencies on the JDK we compute these
789 // offsets at run-time.
790 static int _clazz_offset;
791 static int _parameterTypes_offset;
792 static int _exceptionTypes_offset;
793 static int _slot_offset;
794 static int _modifiers_offset;
795 static int _signature_offset;
796 static int _annotations_offset;
797 static int _parameter_annotations_offset;
798
799 static void compute_offsets();
800 public:
801 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
802
803 // Allocation
804 static Handle create(TRAPS);
805
806 // Accessors
807 static oop clazz(oop reflect);
808 static void set_clazz(oop reflect, oop value);
809
810 static oop parameter_types(oop constructor);
811 static void set_parameter_types(oop constructor, oop value);
812
813 static int slot(oop reflect);
814 static void set_slot(oop reflect, int value);
815
816 static void set_exception_types(oop constructor, oop value);
817 static void set_modifiers(oop constructor, int value);
818 static void set_signature(oop constructor, oop value);
819 static void set_annotations(oop constructor, oop value);
820 static void set_parameter_annotations(oop method, oop value);
821
822 // Debugging
823 friend class JavaClasses;
824 };
825
826
827 // Interface to java.lang.reflect.Field objects
828
829 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
830 private:
831 // Note that to reduce dependencies on the JDK we compute these
832 // offsets at run-time.
833 static int _clazz_offset;
834 static int _name_offset;
835 static int _type_offset;
836 static int _slot_offset;
837 static int _modifiers_offset;
838 static int _trusted_final_offset;
839 static int _signature_offset;
840 static int _annotations_offset;
841
842 static void compute_offsets();
843
844 public:
845 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
846
847 // Allocation
848 static Handle create(TRAPS);
849
850 // Accessors
851 static oop clazz(oop reflect);
852 static void set_clazz(oop reflect, oop value);
853
854 static oop name(oop field);
855 static void set_name(oop field, oop value);
856
857 static oop type(oop field);
858 static void set_type(oop field, oop value);
859
860 static int slot(oop reflect);
861 static void set_slot(oop reflect, int value);
862
863 static int modifiers(oop field);
864 static void set_modifiers(oop field, int value);
865
866 static void set_trusted_final(oop field);
867
868 static void set_signature(oop constructor, oop value);
869 static void set_annotations(oop constructor, oop value);
870
871 // Debugging
872 friend class JavaClasses;
873 };
874
875 class java_lang_reflect_Parameter {
876 private:
877 // Note that to reduce dependencies on the JDK we compute these
878 // offsets at run-time.
879 static int _name_offset;
880 static int _modifiers_offset;
881 static int _index_offset;
882 static int _executable_offset;
883
884 static void compute_offsets();
885
886 public:
887 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
888
889 // Allocation
890 static Handle create(TRAPS);
891
892 // Accessors
893 static oop name(oop field);
894 static void set_name(oop field, oop value);
895
896 static int index(oop reflect);
897 static void set_index(oop reflect, int value);
898
899 static int modifiers(oop reflect);
900 static void set_modifiers(oop reflect, int value);
901
902 static oop executable(oop constructor);
903 static void set_executable(oop constructor, oop value);
904
905 friend class JavaClasses;
906 };
907
908 #define MODULE_INJECTED_FIELDS(macro) \
909 macro(java_lang_Module, module_entry, intptr_signature, false)
910
911 class java_lang_Module {
912 private:
913 static int _loader_offset;
914 static int _name_offset;
915 static int _module_entry_offset;
916
917 static void compute_offsets();
918
919 public:
920 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
921
922 // Allocation
923 static Handle create(Handle loader, Handle module_name, TRAPS);
924
925 // Testers
926 static bool is_instance(oop obj);
927
928 // Accessors
929 static oop loader(oop module);
930 static void set_loader(oop module, oop value);
931
932 // CDS
933 static int module_entry_offset() { return _module_entry_offset; }
934
935 static oop name(oop module);
936 static void set_name(oop module, oop value);
937
938 static ModuleEntry* module_entry(oop module);
939 static ModuleEntry* module_entry_raw(oop module);
940 static void set_module_entry(oop module, ModuleEntry* module_entry);
941
942 friend class JavaClasses;
943 };
944
945 #define CONSTANTPOOL_INJECTED_FIELDS(macro) \
946 macro(reflect_ConstantPool, vmholder, object_signature, false)
947
948 // Interface to jdk.internal.reflect.ConstantPool objects
949 class reflect_ConstantPool {
950 private:
951 // Note that to reduce dependencies on the JDK we compute these
952 // offsets at run-time. This field is the oop offset for the
953 // actual constant pool, previously called constantPoolOop.
954 static int _vmholder_offset;
955
956 static void compute_offsets();
957
958 public:
959 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
960
961 // Allocation
962 static Handle create(TRAPS);
963
964 // Accessors
965 static void set_cp(oop reflect, ConstantPool* value);
966
967 static ConstantPool* get_cp(oop reflect);
968
969 // Debugging
970 friend class JavaClasses;
971 };
972
973
974 // Interface to java.lang primitive type boxing objects:
975 // - java.lang.Boolean
976 // - java.lang.Character
977 // - java.lang.Float
978 // - java.lang.Double
979 // - java.lang.Byte
980 // - java.lang.Short
981 // - java.lang.Integer
982 // - java.lang.Long
983
984 // This could be separated out into 8 individual classes.
985
986 class java_lang_boxing_object: AllStatic {
987 private:
988 static int _value_offset;
989 static int _long_value_offset;
990
991 static void compute_offsets();
992 static oop initialize_and_allocate(BasicType type, TRAPS);
993 public:
994 // Allocation. Returns a boxed value, or null for invalid type.
995 static oop create(BasicType type, jvalue* value, TRAPS);
996 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
997 static BasicType get_value(oop box, jvalue* value);
998 static BasicType set_value(oop box, jvalue* value);
999 static BasicType basic_type(oop box);
1000 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
1001 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
1002 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
1003 static void print(BasicType type, jvalue* value, outputStream* st);
1004
1005 static int value_offset(BasicType type) {
1006 return is_double_word_type(type) ? _long_value_offset : _value_offset;
1007 }
1008
1009 static void serialize_offsets(SerializeClosure* f);
1010
1011 // Debugging
1012 friend class JavaClasses;
1013 };
1014
1015
1016
1017 // Interface to java.lang.ref.Reference objects
1018
1019 class java_lang_ref_Reference: AllStatic {
1020 static int _referent_offset;
1021 static int _queue_offset;
1022 static int _next_offset;
1023 static int _discovered_offset;
1024
1025 static bool _offsets_initialized;
1026
1027 public:
1028 // Accessors
1029 static inline oop weak_referent_no_keepalive(oop ref);
1030 static inline oop weak_referent(oop ref);
1031 static inline oop phantom_referent_no_keepalive(oop ref);
1032 static inline oop unknown_referent_no_keepalive(oop ref);
1033 static inline void clear_referent(oop ref);
1034 static inline void clear_referent_raw(oop ref);
1035 static inline HeapWord* referent_addr_raw(oop ref);
1036 static inline oop next(oop ref);
1037 static inline void set_next(oop ref, oop value);
1038 static inline void set_next_raw(oop ref, oop value);
1039 static inline HeapWord* next_addr_raw(oop ref);
1040 static inline oop discovered(oop ref);
1041 static inline void set_discovered(oop ref, oop value);
1042 static inline void set_discovered_raw(oop ref, oop value);
1043 static inline HeapWord* discovered_addr_raw(oop ref);
1044 static bool is_referent_field(oop obj, ptrdiff_t offset);
1045 static inline bool is_final(oop ref);
1046 static inline bool is_phantom(oop ref);
1047 static inline bool is_weak(oop ref);
1048 static inline bool is_soft(oop ref);
1049
1050 static int referent_offset() { CHECK_INIT(_referent_offset); }
1051 static int queue_offset() { CHECK_INIT(_queue_offset); }
1052 static int next_offset() { CHECK_INIT(_next_offset); }
1053 static int discovered_offset() { CHECK_INIT(_discovered_offset); }
1054
1055 static void compute_offsets();
1056 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1057 };
1058
1059
1060 // Interface to java.lang.ref.SoftReference objects
1061
1062 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
1063 static int _timestamp_offset;
1064 static int _static_clock_offset;
1065
1066 public:
1067 // Accessors
1068 static jlong timestamp(oop ref);
1069
1070 // Accessors for statics
1071 static jlong clock();
1072 static void set_clock(jlong value);
1073
1074 static void compute_offsets();
1075 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1076 };
1077
1078 // Interface to java.lang.invoke.MethodHandle objects
1079
1080 class java_lang_invoke_MethodHandle: AllStatic {
1081 friend class JavaClasses;
1082
1083 private:
1084 static int _type_offset; // the MethodType of this MH
1085 static int _form_offset; // the LambdaForm of this MH
1086
1087 static void compute_offsets();
1088
1089 public:
1090 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1091
1092 // Accessors
1093 static oop type(oop mh);
1094 static void set_type(oop mh, oop mtype);
1095
1096 static oop form(oop mh);
1097 static void set_form(oop mh, oop lform);
1098
1099 // Testers
1100 static bool is_subclass(Klass* klass) {
1101 return klass->is_subclass_of(vmClasses::MethodHandle_klass());
1102 }
1103 static bool is_instance(oop obj);
1104
1105 // Accessors for code generation:
1106 static int type_offset() { CHECK_INIT(_type_offset); }
1107 static int form_offset() { CHECK_INIT(_form_offset); }
1108 };
1109
1110 // Interface to java.lang.invoke.DirectMethodHandle objects
1111
1112 class java_lang_invoke_DirectMethodHandle: AllStatic {
1113 friend class JavaClasses;
1114
1115 private:
1116 static int _member_offset; // the MemberName of this DMH
1117
1118 static void compute_offsets();
1119
1120 public:
1121 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1122
1123 // Accessors
1124 static oop member(oop mh);
1125
1126 // Testers
1127 static bool is_subclass(Klass* klass) {
1128 return klass->is_subclass_of(vmClasses::DirectMethodHandle_klass());
1129 }
1130 static bool is_instance(oop obj);
1131
1132 // Accessors for code generation:
1133 static int member_offset() { CHECK_INIT(_member_offset); }
1134 };
1135
1136 // Interface to java.lang.invoke.LambdaForm objects
1137 // (These are a private interface for managing adapter code generation.)
1138
1139 class java_lang_invoke_LambdaForm: AllStatic {
1140 friend class JavaClasses;
1141
1142 private:
1143 static int _vmentry_offset; // type is MemberName
1144
1145 static void compute_offsets();
1146
1147 public:
1148 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1149
1150 // Accessors
1151 static oop vmentry(oop lform);
1152
1153 // Testers
1154 static bool is_subclass(Klass* klass) {
1155 return vmClasses::LambdaForm_klass() != nullptr &&
1156 klass->is_subclass_of(vmClasses::LambdaForm_klass());
1157 }
1158 static bool is_instance(oop obj);
1159
1160 // Accessors for code generation:
1161 static int vmentry_offset() { CHECK_INIT(_vmentry_offset); }
1162 };
1163
1164 // Interface to java.lang.invoke.NativeEntryPoint objects
1165 // (These are a private interface for managing adapter code generation.)
1166
1167 class jdk_internal_foreign_abi_NativeEntryPoint: AllStatic {
1168 friend class JavaClasses;
1169
1170 private:
1171 static int _method_type_offset;
1172 static int _downcall_stub_address_offset;
1173
1174 static void compute_offsets();
1175
1176 public:
1177 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1178
1179 // Accessors
1180 static oop method_type(oop entry);
1181 static jlong downcall_stub_address(oop entry);
1182
1183 // Testers
1184 static bool is_subclass(Klass* klass) {
1185 return vmClasses::NativeEntryPoint_klass() != nullptr &&
1186 klass->is_subclass_of(vmClasses::NativeEntryPoint_klass());
1187 }
1188 static bool is_instance(oop obj);
1189
1190 // Accessors for code generation:
1191 static int method_type_offset_in_bytes() { return _method_type_offset; }
1192 static int downcall_stub_address_offset_in_bytes() { return _downcall_stub_address_offset; }
1193 };
1194
1195 class jdk_internal_foreign_abi_ABIDescriptor: AllStatic {
1196 friend class JavaClasses;
1197
1198 private:
1199 static int _inputStorage_offset;
1200 static int _outputStorage_offset;
1201 static int _volatileStorage_offset;
1202 static int _stackAlignment_offset;
1203 static int _shadowSpace_offset;
1204 static int _scratch1_offset;
1205 static int _scratch2_offset;
1206
1207 static void compute_offsets();
1208
1209 public:
1210 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1211
1212 // Accessors
1213 static objArrayOop inputStorage(oop entry);
1214 static objArrayOop outputStorage(oop entry);
1215 static objArrayOop volatileStorage(oop entry);
1216 static jint stackAlignment(oop entry);
1217 static jint shadowSpace(oop entry);
1218 static oop scratch1(oop entry);
1219 static oop scratch2(oop entry);
1220
1221 // Testers
1222 static bool is_subclass(Klass* klass) {
1223 return vmClasses::ABIDescriptor_klass() != nullptr &&
1224 klass->is_subclass_of(vmClasses::ABIDescriptor_klass());
1225 }
1226 static bool is_instance(oop obj);
1227 };
1228
1229 class jdk_internal_foreign_abi_VMStorage: AllStatic {
1230 friend class JavaClasses;
1231
1232 private:
1233 static int _type_offset;
1234 static int _indexOrOffset_offset;
1235 static int _segmentMaskOrSize_offset;
1236 static int _debugName_offset;
1237
1238 static void compute_offsets();
1239
1240 public:
1241 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1242
1243 // Accessors
1244 static jbyte type(oop entry);
1245 static jint index_or_offset(oop entry);
1246 static jshort segment_mask_or_size(oop entry);
1247 static oop debugName(oop entry);
1248
1249 // Testers
1250 static bool is_subclass(Klass* klass) {
1251 return vmClasses::VMStorage_klass() != nullptr &&
1252 klass->is_subclass_of(vmClasses::VMStorage_klass());
1253 }
1254 static bool is_instance(oop obj);
1255 };
1256
1257 class jdk_internal_foreign_abi_CallConv: AllStatic {
1258 friend class JavaClasses;
1259
1260 private:
1261 static int _argRegs_offset;
1262 static int _retRegs_offset;
1263
1264 static void compute_offsets();
1265
1266 public:
1267 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1268
1269 // Accessors
1270 static objArrayOop argRegs(oop entry);
1271 static objArrayOop retRegs(oop entry);
1272
1273 // Testers
1274 static bool is_subclass(Klass* klass) {
1275 return vmClasses::CallConv_klass() != nullptr &&
1276 klass->is_subclass_of(vmClasses::CallConv_klass());
1277 }
1278 static bool is_instance(oop obj);
1279 };
1280
1281 // Interface to java.lang.invoke.MemberName objects
1282 // (These are a private interface for Java code to query the class hierarchy.)
1283
1284 #define RESOLVEDMETHOD_INJECTED_FIELDS(macro) \
1285 macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false)
1286
1287 class java_lang_invoke_ResolvedMethodName : AllStatic {
1288 friend class JavaClasses;
1289
1290 static int _vmtarget_offset;
1291 static int _vmholder_offset;
1292
1293 static void compute_offsets();
1294 public:
1295 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1296
1297 static int vmtarget_offset() { CHECK_INIT(_vmtarget_offset); }
1298
1299 static Method* vmtarget(oop resolved_method);
1300 static void set_vmtarget(oop resolved_method, Method* method);
1301
1302 static void set_vmholder(oop resolved_method, oop holder);
1303
1304 // find or create resolved member name
1305 static oop find_resolved_method(const methodHandle& m, TRAPS);
1306
1307 static bool is_instance(oop resolved_method);
1308 };
1309
1310
1311 #define MEMBERNAME_INJECTED_FIELDS(macro) \
1312 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false)
1313
1314
1315 class java_lang_invoke_MemberName: AllStatic {
1316 friend class JavaClasses;
1317
1318 private:
1319 // From java.lang.invoke.MemberName:
1320 // private Class<?> clazz; // class in which the method is defined
1321 // private String name; // may be null if not yet materialized
1322 // private Object type; // may be null if not yet materialized
1323 // private int flags; // modifier bits; see reflect.Modifier
1324 // private ResolvedMethodName method; // holds VM-specific target value
1325 // private intptr_t vmindex; // member index within class or interface
1326 static int _clazz_offset;
1327 static int _name_offset;
1328 static int _type_offset;
1329 static int _flags_offset;
1330 static int _method_offset;
1331 static int _vmindex_offset;
1332
1333 static void compute_offsets();
1334
1335 public:
1336 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1337 // Accessors
1338 static oop clazz(oop mname);
1339 static void set_clazz(oop mname, oop clazz);
1340
1341 static oop type(oop mname);
1342 static void set_type(oop mname, oop type);
1343
1344 static oop name(oop mname);
1345 static void set_name(oop mname, oop name);
1346
1347 static int flags(oop mname);
1348 static void set_flags(oop mname, int flags);
1349
1350 // Link through ResolvedMethodName field to get Method*
1351 static Method* vmtarget(oop mname);
1352 static void set_method(oop mname, oop method);
1353
1354 static intptr_t vmindex(oop mname);
1355 static void set_vmindex(oop mname, intptr_t index);
1356
1357 // Testers
1358 static bool is_subclass(Klass* klass) {
1359 return klass->is_subclass_of(vmClasses::MemberName_klass());
1360 }
1361 static bool is_instance(oop obj);
1362
1363 static bool is_method(oop obj);
1364
1365 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1366 enum {
1367 MN_IS_METHOD = 0x00010000, // method (not constructor)
1368 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
1369 MN_IS_FIELD = 0x00040000, // field
1370 MN_IS_TYPE = 0x00080000, // nested type
1371 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected
1372 MN_TRUSTED_FINAL = 0x00200000, // trusted final field
1373 MN_HIDDEN_MEMBER = 0x00400000, // @Hidden annotation detected
1374 MN_REFERENCE_KIND_SHIFT = 24, // refKind
1375 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1376 MN_NESTMATE_CLASS = 0x00000001,
1377 MN_HIDDEN_CLASS = 0x00000002,
1378 MN_STRONG_LOADER_LINK = 0x00000004,
1379 MN_ACCESS_VM_ANNOTATIONS = 0x00000008,
1380 // Lookup modes
1381 MN_MODULE_MODE = 0x00000010,
1382 MN_UNCONDITIONAL_MODE = 0x00000020,
1383 MN_TRUSTED_MODE = -1
1384 };
1385
1386 // Accessors for code generation:
1387 static int clazz_offset() { CHECK_INIT(_clazz_offset); }
1388 static int type_offset() { CHECK_INIT(_type_offset); }
1389 static int flags_offset() { CHECK_INIT(_flags_offset); }
1390 static int method_offset() { CHECK_INIT(_method_offset); }
1391 static int vmindex_offset() { CHECK_INIT(_vmindex_offset); }
1392 };
1393
1394
1395 // Interface to java.lang.invoke.MethodType objects
1396
1397 class java_lang_invoke_MethodType: AllStatic {
1398 friend class JavaClasses;
1399
1400 private:
1401 static int _rtype_offset;
1402 static int _ptypes_offset;
1403
1404 static void compute_offsets();
1405
1406 public:
1407 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1408 // Accessors
1409 static oop rtype(oop mt);
1410 static objArrayOop ptypes(oop mt);
1411
1412 static oop ptype(oop mt, int index);
1413 static int ptype_count(oop mt);
1414
1415 static int ptype_slot_count(oop mt); // extra counts for long/double
1416 static int rtype_slot_count(oop mt); // extra counts for long/double
1417
1418 static Symbol* as_signature(oop mt, bool intern_if_not_found);
1419 static void print_signature(oop mt, outputStream* st);
1420
1421 static bool is_instance(oop obj);
1422
1423 static bool equals(oop mt1, oop mt2);
1424
1425 // Accessors for code generation:
1426 static int rtype_offset() { CHECK_INIT(_rtype_offset); }
1427 static int ptypes_offset() { CHECK_INIT(_ptypes_offset); }
1428 };
1429
1430
1431 // Interface to java.lang.invoke.CallSite objects
1432 #define CALLSITE_INJECTED_FIELDS(macro) \
1433 macro(java_lang_invoke_CallSite, vmdependencies, intptr_signature, false) \
1434 macro(java_lang_invoke_CallSite, last_cleanup, long_signature, false)
1435
1436 class java_lang_invoke_CallSite: AllStatic {
1437 friend class JavaClasses;
1438
1439 private:
1440 static int _target_offset;
1441 static int _vmdependencies_offset;
1442 static int _last_cleanup_offset;
1443
1444 static void compute_offsets();
1445
1446 public:
1447 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1448 // Accessors
1449 static oop target( oop site);
1450 static void set_target( oop site, oop target);
1451 static void set_target_volatile( oop site, oop target);
1452
1453 static DependencyContext vmdependencies(oop call_site);
1454
1455 // Testers
1456 static bool is_subclass(Klass* klass) {
1457 return klass->is_subclass_of(vmClasses::CallSite_klass());
1458 }
1459 static bool is_instance(oop obj);
1460
1461 // Accessors for code generation:
1462 static int target_offset() { CHECK_INIT(_target_offset); }
1463 };
1464
1465 // Interface to java.lang.invoke.ConstantCallSite objects
1466
1467 class java_lang_invoke_ConstantCallSite: AllStatic {
1468 friend class JavaClasses;
1469
1470 private:
1471 static int _is_frozen_offset;
1472
1473 static void compute_offsets();
1474
1475 public:
1476 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1477 // Accessors
1478 static jboolean is_frozen(oop site);
1479
1480 // Testers
1481 static bool is_subclass(Klass* klass) {
1482 return klass->is_subclass_of(vmClasses::ConstantCallSite_klass());
1483 }
1484 static bool is_instance(oop obj);
1485 };
1486
1487 // Interface to java.lang.ClassLoader objects
1488
1489 #define CLASSLOADER_INJECTED_FIELDS(macro) \
1490 macro(java_lang_ClassLoader, loader_data, intptr_signature, false)
1491
1492 class java_lang_ClassLoader : AllStatic {
1493 private:
1494 static int _loader_data_offset;
1495 static int _parent_offset;
1496 static int _parallelCapable_offset;
1497 static int _name_offset;
1498 static int _nameAndId_offset;
1499 static int _unnamedModule_offset;
1500
1501 static void compute_offsets();
1502
1503 public:
1504 // Support for CDS
1505 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1506 static int loader_data_offset() { return _loader_data_offset; }
1507
1508 static ClassLoaderData* loader_data_acquire(oop loader);
1509 static ClassLoaderData* loader_data(oop loader);
1510 static void release_set_loader_data(oop loader, ClassLoaderData* new_data);
1511
1512 static oop parent(oop loader);
1513 static oop parent_no_keepalive(oop loader);
1514 static oop name(oop loader);
1515 static oop nameAndId(oop loader);
1516 static bool isAncestor(oop loader, oop cl);
1517
1518 // Support for parallelCapable field
1519 static bool parallelCapable(oop the_class_mirror);
1520
1521 static bool is_trusted_loader(oop loader);
1522
1523 // Testers
1524 static bool is_subclass(Klass* klass) {
1525 return klass->is_subclass_of(vmClasses::ClassLoader_klass());
1526 }
1527 static bool is_instance(oop obj);
1528
1529 static oop unnamedModule(oop loader);
1530
1531 // Debugging
1532 friend class JavaClasses;
1533 };
1534
1535
1536 // Interface to java.lang.System objects
1537
1538 class java_lang_System : AllStatic {
1539 private:
1540 static int _static_in_offset;
1541 static int _static_out_offset;
1542 static int _static_err_offset;
1543
1544 public:
1545 static int in_offset() { CHECK_INIT(_static_in_offset); }
1546 static int out_offset() { CHECK_INIT(_static_out_offset); }
1547 static int err_offset() { CHECK_INIT(_static_err_offset); }
1548
1549 static void compute_offsets();
1550 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1551
1552 // Debugging
1553 friend class JavaClasses;
1554 };
1555
1556
1557 // Interface to java.lang.StackTraceElement objects
1558
1559 class java_lang_StackTraceElement: AllStatic {
1560 private:
1561 static int _declaringClassObject_offset;
1562 static int _classLoaderName_offset;
1563 static int _moduleName_offset;
1564 static int _moduleVersion_offset;
1565 static int _declaringClass_offset;
1566 static int _methodName_offset;
1567 static int _fileName_offset;
1568 static int _lineNumber_offset;
1569
1570 // Setters
1571 static void set_classLoaderName(oop element, oop value);
1572 static void set_moduleName(oop element, oop value);
1573 static void set_moduleVersion(oop element, oop value);
1574 static void set_declaringClass(oop element, oop value);
1575 static void set_methodName(oop element, oop value);
1576 static void set_fileName(oop element, oop value);
1577 static void set_lineNumber(oop element, int value);
1578 static void set_declaringClassObject(oop element, oop value);
1579
1580 static void decode_file_and_line(Handle java_mirror, InstanceKlass* holder, int version,
1581 const methodHandle& method, int bci,
1582 Symbol*& source, oop& source_file, int& line_number, TRAPS);
1583
1584 public:
1585 // Create an instance of StackTraceElement
1586 static oop create(const methodHandle& method, int bci, TRAPS);
1587
1588 static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1589 int version, int bci, Symbol* name, TRAPS);
1590
1591 static void compute_offsets();
1592 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1593
1594 #if INCLUDE_JVMCI
1595 static void decode(const methodHandle& method, int bci, Symbol*& fileName, int& lineNumber, TRAPS);
1596 #endif
1597
1598 // Debugging
1599 friend class JavaClasses;
1600 };
1601
1602
1603 class Backtrace: AllStatic {
1604 public:
1605 // Helper backtrace functions to store bci|version together.
1606 static int merge_bci_and_version(int bci, int version);
1607 static int merge_mid_and_cpref(int mid, int cpref);
1608 static int bci_at(unsigned int merged);
1609 static int version_at(unsigned int merged);
1610 static int mid_at(unsigned int merged);
1611 static int cpref_at(unsigned int merged);
1612 static int get_line_number(Method* method, int bci);
1613 static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1614
1615 // Debugging
1616 friend class JavaClasses;
1617 };
1618
1619 class java_lang_ClassFrameInfo: AllStatic {
1620 private:
1621 static int _classOrMemberName_offset;
1622 static int _flags_offset;
1623
1624 public:
1625 static oop classOrMemberName(oop info);
1626 static int flags(oop info);
1627
1628 // Setters
1629 static void init_class(Handle stackFrame, const methodHandle& m);
1630 static void init_method(Handle stackFrame, const methodHandle& m, TRAPS);
1631
1632 static void compute_offsets();
1633 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1634
1635 // Debugging
1636 friend class JavaClasses;
1637 };
1638
1639 // Interface to java.lang.StackFrameInfo objects
1640
1641 #define STACKFRAMEINFO_INJECTED_FIELDS(macro) \
1642 macro(java_lang_StackFrameInfo, version, short_signature, false)
1643
1644 class java_lang_StackFrameInfo: AllStatic {
1645 private:
1646 static int _type_offset;
1647 static int _name_offset;
1648 static int _bci_offset;
1649 static int _version_offset;
1650 static int _contScope_offset;
1651
1652 public:
1653 // Getters
1654 static oop name(oop info);
1655 static oop type(oop info);
1656 static Method* get_method(oop info);
1657
1658 // Setters
1659 static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, oop cont, TRAPS);
1660 static void set_name(oop info, oop value);
1661 static void set_type(oop info, oop value);
1662 static void set_bci(oop info, int value);
1663
1664 static void set_version(oop info, short value);
1665 static void set_contScope(oop info, oop value);
1666
1667 static void compute_offsets();
1668 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1669
1670 static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS);
1671
1672 // Debugging
1673 friend class JavaClasses;
1674 };
1675
1676 class java_lang_LiveStackFrameInfo: AllStatic {
1677 private:
1678 static int _monitors_offset;
1679 static int _locals_offset;
1680 static int _operands_offset;
1681 static int _mode_offset;
1682
1683 public:
1684 static void set_monitors(oop info, oop value);
1685 static void set_locals(oop info, oop value);
1686 static void set_operands(oop info, oop value);
1687 static void set_mode(oop info, int value);
1688
1689 static void compute_offsets();
1690 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1691
1692 // Debugging
1693 friend class JavaClasses;
1694 };
1695
1696 // Interface to java.lang.reflect.RecordComponent objects
1697
1698 class java_lang_reflect_RecordComponent: AllStatic {
1699 private:
1700 static int _clazz_offset;
1701 static int _name_offset;
1702 static int _type_offset;
1703 static int _accessor_offset;
1704 static int _signature_offset;
1705 static int _annotations_offset;
1706 static int _typeAnnotations_offset;
1707
1708 // Setters
1709 static void set_clazz(oop element, oop value);
1710 static void set_name(oop element, oop value);
1711 static void set_type(oop element, oop value);
1712 static void set_accessor(oop element, oop value);
1713 static void set_signature(oop element, oop value);
1714 static void set_annotations(oop element, oop value);
1715 static void set_typeAnnotations(oop element, oop value);
1716
1717 public:
1718 // Create an instance of RecordComponent
1719 static oop create(InstanceKlass* holder, RecordComponent* component, TRAPS);
1720
1721 static void compute_offsets();
1722 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1723
1724 // Debugging
1725 friend class JavaClasses;
1726 };
1727
1728
1729 // Interface to java.lang.AssertionStatusDirectives objects
1730
1731 class java_lang_AssertionStatusDirectives: AllStatic {
1732 private:
1733 static int _classes_offset;
1734 static int _classEnabled_offset;
1735 static int _packages_offset;
1736 static int _packageEnabled_offset;
1737 static int _deflt_offset;
1738
1739 public:
1740 // Setters
1741 static void set_classes(oop obj, oop val);
1742 static void set_classEnabled(oop obj, oop val);
1743 static void set_packages(oop obj, oop val);
1744 static void set_packageEnabled(oop obj, oop val);
1745 static void set_deflt(oop obj, bool val);
1746
1747 static void compute_offsets();
1748 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1749
1750 // Debugging
1751 friend class JavaClasses;
1752 };
1753
1754
1755 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1756 private:
1757 static int _owner_offset;
1758 public:
1759 static void compute_offsets();
1760 static oop get_owner_threadObj(oop obj);
1761 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1762 };
1763
1764 // Interface to jdk.internal.misc.UnsafeConsants
1765
1766 class jdk_internal_misc_UnsafeConstants : AllStatic {
1767 public:
1768 static void set_unsafe_constants();
1769 static void compute_offsets() { }
1770 static void serialize_offsets(SerializeClosure* f) { }
1771 };
1772
1773 // Interface to jdk.internal.vm.vector.VectorSupport.VectorPayload objects
1774
1775 class vector_VectorPayload : AllStatic {
1776 private:
1777 static int _payload_offset;
1778 public:
1779 static void set_payload(oop o, oop val);
1780
1781 static void compute_offsets();
1782 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1783
1784 // Testers
1785 static bool is_subclass(Klass* klass) {
1786 return klass->is_subclass_of(vmClasses::vector_VectorPayload_klass());
1787 }
1788 static bool is_instance(oop obj);
1789 };
1790
1791 class java_lang_Integer : AllStatic {
1792 public:
1793 static jint value(oop obj);
1794 };
1795
1796 class java_lang_Long : AllStatic {
1797 public:
1798 static jlong value(oop obj);
1799 };
1800
1801 class java_lang_Character : AllStatic {
1802 public:
1803 static jchar value(oop obj);
1804 };
1805
1806 class java_lang_Short : AllStatic {
1807 public:
1808 static jshort value(oop obj);
1809 };
1810
1811 class java_lang_Byte : AllStatic {
1812 public:
1813 static jbyte value(oop obj);
1814 };
1815
1816 class java_lang_Boolean : AllStatic {
1817 private:
1818 static int _static_TRUE_offset;
1819 static int _static_FALSE_offset;
1820 public:
1821 static Symbol* symbol();
1822 static void compute_offsets(InstanceKlass* k);
1823 static oop get_TRUE(InstanceKlass *k);
1824 static oop get_FALSE(InstanceKlass *k);
1825 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1826 static jboolean value(oop obj);
1827 };
1828
1829 class java_lang_Integer_IntegerCache : AllStatic {
1830 private:
1831 static int _static_cache_offset;
1832 public:
1833 static Symbol* symbol();
1834 static void compute_offsets(InstanceKlass* k);
1835 static objArrayOop cache(InstanceKlass *k);
1836 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1837 };
1838
1839 class java_lang_Long_LongCache : AllStatic {
1840 private:
1841 static int _static_cache_offset;
1842 public:
1843 static Symbol* symbol();
1844 static void compute_offsets(InstanceKlass* k);
1845 static objArrayOop cache(InstanceKlass *k);
1846 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1847 };
1848
1849 class java_lang_Character_CharacterCache : AllStatic {
1850 private:
1851 static int _static_cache_offset;
1852 public:
1853 static Symbol* symbol();
1854 static void compute_offsets(InstanceKlass* k);
1855 static objArrayOop cache(InstanceKlass *k);
1856 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1857 };
1858
1859 class java_lang_Short_ShortCache : AllStatic {
1860 private:
1861 static int _static_cache_offset;
1862 public:
1863 static Symbol* symbol();
1864 static void compute_offsets(InstanceKlass* k);
1865 static objArrayOop cache(InstanceKlass *k);
1866 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1867 };
1868
1869 class java_lang_Byte_ByteCache : AllStatic {
1870 private:
1871 static int _static_cache_offset;
1872 public:
1873 static Symbol* symbol();
1874 static void compute_offsets(InstanceKlass* k);
1875 static objArrayOop cache(InstanceKlass *k);
1876 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1877 };
1878
1879
1880 // Interface to java.lang.InternalError objects
1881
1882 #define INTERNALERROR_INJECTED_FIELDS(macro) \
1883 macro(java_lang_InternalError, during_unsafe_access, bool_signature, false)
1884
1885 class java_lang_InternalError : AllStatic {
1886 private:
1887 static int _during_unsafe_access_offset;
1888 public:
1889 static jboolean during_unsafe_access(oop internal_error);
1890 static void set_during_unsafe_access(oop internal_error);
1891 static void compute_offsets();
1892 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1893 };
1894
1895 // Use to declare fields that need to be injected into Java classes
1896 // for the JVM to use. The name_index and signature_index are
1897 // declared in vmSymbols. The may_be_java flag is used to declare
1898 // fields that might already exist in Java but should be injected if
1899 // they don't. Otherwise the field is unconditionally injected and
1900 // the JVM uses the injected one. This is to ensure that name
1901 // collisions don't occur. In general may_be_java should be false
1902 // unless there's a good reason.
1903
1904 class InjectedField {
1905 public:
1906 const vmClassID klass_id;
1907 const vmSymbolID name_index;
1908 const vmSymbolID signature_index;
1909 const bool may_be_java;
1910
1911
1912 InstanceKlass* klass() const { return vmClasses::klass_at(klass_id); }
1913 Symbol* name() const { return lookup_symbol(name_index); }
1914 Symbol* signature() const { return lookup_symbol(signature_index); }
1915
1916 int compute_offset();
1917
1918 // Find the Symbol for this index
1919 static Symbol* lookup_symbol(vmSymbolID symbol_index) {
1920 return Symbol::vm_symbol_at(symbol_index);
1921 }
1922 };
1923
1924
1925 // Interface to hard-coded offset checking
1926
1927 enum class InjectedFieldID : int;
1928
1929 class JavaClasses : AllStatic {
1930 private:
1931
1932 static InjectedField _injected_fields[];
1933
1934 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1935 public:
1936
1937 static int compute_injected_offset(InjectedFieldID id);
1938
1939 static void compute_offsets();
1940 static void check_offsets() PRODUCT_RETURN;
1941 static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN;
1942 static InjectedField* get_injected(Symbol* class_name, int* field_count);
1943 static bool is_supported_for_archiving(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(false);
1944
1945 static void compute_offset(int &dest_offset,
1946 InstanceKlass* ik, Symbol* name_symbol, Symbol* signature_symbol,
1947 bool is_static = false);
1948 static void compute_offset(int& dest_offset, InstanceKlass* ik,
1949 const char* name_string, Symbol* signature_symbol,
1950 bool is_static = false);
1951 };
1952
1953 #undef CHECK_INIT
1954
1955 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP