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