Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/oops/instanceKlass.hpp
64440 views
1
/*
2
* Copyright (c) 1997, 2021, 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_OOPS_INSTANCEKLASS_HPP
26
#define SHARE_OOPS_INSTANCEKLASS_HPP
27
28
#include "memory/referenceType.hpp"
29
#include "oops/annotations.hpp"
30
#include "oops/constMethod.hpp"
31
#include "oops/fieldInfo.hpp"
32
#include "oops/instanceOop.hpp"
33
#include "runtime/handles.hpp"
34
#include "utilities/accessFlags.hpp"
35
#include "utilities/align.hpp"
36
#include "utilities/macros.hpp"
37
#if INCLUDE_JFR
38
#include "jfr/support/jfrKlassExtension.hpp"
39
#endif
40
41
class klassItable;
42
class RecordComponent;
43
44
// An InstanceKlass is the VM level representation of a Java class.
45
// It contains all information needed for at class at execution runtime.
46
47
// InstanceKlass embedded field layout (after declared fields):
48
// [EMBEDDED Java vtable ] size in words = vtable_len
49
// [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
50
// The embedded nonstatic oop-map blocks are short pairs (offset, length)
51
// indicating where oops are located in instances of this klass.
52
// [EMBEDDED implementor of the interface] only exist for interface
53
54
55
// forward declaration for class -- see below for definition
56
#if INCLUDE_JVMTI
57
class BreakpointInfo;
58
#endif
59
class ClassFileParser;
60
class ClassFileStream;
61
class KlassDepChange;
62
class DependencyContext;
63
class fieldDescriptor;
64
class jniIdMapBase;
65
class JNIid;
66
class JvmtiCachedClassFieldMap;
67
class nmethodBucket;
68
class OopMapCache;
69
class InterpreterOopMap;
70
class PackageEntry;
71
class ModuleEntry;
72
73
// This is used in iterators below.
74
class FieldClosure: public StackObj {
75
public:
76
virtual void do_field(fieldDescriptor* fd) = 0;
77
};
78
79
// Print fields.
80
// If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
81
class FieldPrinter: public FieldClosure {
82
oop _obj;
83
outputStream* _st;
84
public:
85
FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {}
86
void do_field(fieldDescriptor* fd);
87
};
88
89
// Describes where oops are located in instances of this klass.
90
class OopMapBlock {
91
public:
92
// Byte offset of the first oop mapped by this block.
93
int offset() const { return _offset; }
94
void set_offset(int offset) { _offset = offset; }
95
96
// Number of oops in this block.
97
uint count() const { return _count; }
98
void set_count(uint count) { _count = count; }
99
100
void increment_count(int diff) { _count += diff; }
101
102
int offset_span() const { return _count * heapOopSize; }
103
104
int end_offset() const {
105
return offset() + offset_span();
106
}
107
108
bool is_contiguous(int another_offset) const {
109
return another_offset == end_offset();
110
}
111
112
// sizeof(OopMapBlock) in words.
113
static const int size_in_words() {
114
return align_up((int)sizeof(OopMapBlock), wordSize) >>
115
LogBytesPerWord;
116
}
117
118
static int compare_offset(const OopMapBlock* a, const OopMapBlock* b) {
119
return a->offset() - b->offset();
120
}
121
122
private:
123
int _offset;
124
uint _count;
125
};
126
127
struct JvmtiCachedClassFileData;
128
129
class InstanceKlass: public Klass {
130
friend class VMStructs;
131
friend class JVMCIVMStructs;
132
friend class ClassFileParser;
133
friend class CompileReplay;
134
135
public:
136
static const KlassID ID = InstanceKlassID;
137
138
protected:
139
InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id = ID);
140
141
public:
142
InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
143
144
// See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description
145
// of the class loading & initialization procedure, and the use of the states.
146
enum ClassState {
147
allocated, // allocated (but not yet linked)
148
loaded, // loaded and inserted in class hierarchy (but not linked yet)
149
linked, // successfully linked/verified (but not initialized yet)
150
being_initialized, // currently running class initializer
151
fully_initialized, // initialized (successfull final state)
152
initialization_error // error happened during initialization
153
};
154
155
private:
156
static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS);
157
158
protected:
159
// If you add a new field that points to any metaspace object, you
160
// must add this field to InstanceKlass::metaspace_pointers_do().
161
162
// Annotations for this class
163
Annotations* _annotations;
164
// Package this class is defined in
165
PackageEntry* _package_entry;
166
// Array classes holding elements of this class.
167
ObjArrayKlass* volatile _array_klasses;
168
// Constant pool for this class.
169
ConstantPool* _constants;
170
// The InnerClasses attribute and EnclosingMethod attribute. The
171
// _inner_classes is an array of shorts. If the class has InnerClasses
172
// attribute, then the _inner_classes array begins with 4-tuples of shorts
173
// [inner_class_info_index, outer_class_info_index,
174
// inner_name_index, inner_class_access_flags] for the InnerClasses
175
// attribute. If the EnclosingMethod attribute exists, it occupies the
176
// last two shorts [class_index, method_index] of the array. If only
177
// the InnerClasses attribute exists, the _inner_classes array length is
178
// number_of_inner_classes * 4. If the class has both InnerClasses
179
// and EnclosingMethod attributes the _inner_classes array length is
180
// number_of_inner_classes * 4 + enclosing_method_attribute_size.
181
Array<jushort>* _inner_classes;
182
183
// The NestMembers attribute. An array of shorts, where each is a
184
// class info index for the class that is a nest member. This data
185
// has not been validated.
186
Array<jushort>* _nest_members;
187
188
// Resolved nest-host klass: either true nest-host or self if we are not
189
// nested, or an error occurred resolving or validating the nominated
190
// nest-host. Can also be set directly by JDK API's that establish nest
191
// relationships.
192
// By always being set it makes nest-member access checks simpler.
193
InstanceKlass* _nest_host;
194
195
// The PermittedSubclasses attribute. An array of shorts, where each is a
196
// class info index for the class that is a permitted subclass.
197
Array<jushort>* _permitted_subclasses;
198
199
// The contents of the Record attribute.
200
Array<RecordComponent*>* _record_components;
201
202
// the source debug extension for this klass, NULL if not specified.
203
// Specified as UTF-8 string without terminating zero byte in the classfile,
204
// it is stored in the instanceklass as a NULL-terminated UTF-8 string
205
const char* _source_debug_extension;
206
207
// Number of heapOopSize words used by non-static fields in this klass
208
// (including inherited fields but after header_size()).
209
int _nonstatic_field_size;
210
int _static_field_size; // number words used by static fields (oop and non-oop) in this klass
211
int _nonstatic_oop_map_size; // size in words of nonstatic oop map blocks
212
int _itable_len; // length of Java itable (in words)
213
214
// The NestHost attribute. The class info index for the class
215
// that is the nest-host of this class. This data has not been validated.
216
u2 _nest_host_index;
217
u2 _this_class_index; // constant pool entry
218
u2 _static_oop_field_count; // number of static oop fields in this klass
219
u2 _java_fields_count; // The number of declared Java fields
220
221
volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
222
223
// _is_marked_dependent can be set concurrently, thus cannot be part of the
224
// _misc_flags.
225
bool _is_marked_dependent; // used for marking during flushing and deoptimization
226
227
// Class states are defined as ClassState (see above).
228
// Place the _init_state here to utilize the unused 2-byte after
229
// _idnum_allocated_count.
230
u1 _init_state; // state of class
231
232
// This can be used to quickly discriminate among the four kinds of
233
// InstanceKlass. This should be an enum (?)
234
static const unsigned _kind_other = 0; // concrete InstanceKlass
235
static const unsigned _kind_reference = 1; // InstanceRefKlass
236
static const unsigned _kind_class_loader = 2; // InstanceClassLoaderKlass
237
static const unsigned _kind_mirror = 3; // InstanceMirrorKlass
238
239
u1 _reference_type; // reference type
240
u1 _kind; // kind of InstanceKlass
241
242
enum {
243
_misc_rewritten = 1 << 0, // methods rewritten.
244
_misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops
245
_misc_should_verify_class = 1 << 2, // allow caching of preverification
246
_misc_unused = 1 << 3, // not currently used
247
_misc_is_contended = 1 << 4, // marked with contended annotation
248
_misc_has_nonstatic_concrete_methods = 1 << 5, // class/superclass/implemented interfaces has non-static, concrete methods
249
_misc_declares_nonstatic_concrete_methods = 1 << 6, // directly declares non-static, concrete methods
250
_misc_has_been_redefined = 1 << 7, // class has been redefined
251
_misc_shared_loading_failed = 1 << 8, // class has been loaded from shared archive
252
_misc_is_scratch_class = 1 << 9, // class is the redefined scratch class
253
_misc_is_shared_boot_class = 1 << 10, // defining class loader is boot class loader
254
_misc_is_shared_platform_class = 1 << 11, // defining class loader is platform class loader
255
_misc_is_shared_app_class = 1 << 12, // defining class loader is app class loader
256
_misc_has_resolved_methods = 1 << 13, // resolved methods table entries added for this class
257
_misc_has_contended_annotations = 1 << 14 // has @Contended annotation
258
};
259
u2 shared_loader_type_bits() const {
260
return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
261
}
262
u2 _misc_flags; // There is more space in access_flags for more flags.
263
264
Thread* _init_thread; // Pointer to current thread doing initialization (to handle recursive initialization)
265
OopMapCache* volatile _oop_map_cache; // OopMapCache for all methods in the klass (allocated lazily)
266
JNIid* _jni_ids; // First JNI identifier for static fields in this class
267
jmethodID* volatile _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none
268
nmethodBucket* volatile _dep_context; // packed DependencyContext structure
269
uint64_t volatile _dep_context_last_cleaned;
270
nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class
271
#if INCLUDE_JVMTI
272
BreakpointInfo* _breakpoints; // bpt lists, managed by Method*
273
// Linked instanceKlasses of previous versions
274
InstanceKlass* _previous_versions;
275
// JVMTI fields can be moved to their own structure - see 6315920
276
// JVMTI: cached class file, before retransformable agent modified it in CFLH
277
JvmtiCachedClassFileData* _cached_class_file;
278
#endif
279
280
#if INCLUDE_JVMTI
281
JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
282
#endif
283
284
NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies
285
286
// Method array.
287
Array<Method*>* _methods;
288
// Default Method Array, concrete methods inherited from interfaces
289
Array<Method*>* _default_methods;
290
// Interfaces (InstanceKlass*s) this class declares locally to implement.
291
Array<InstanceKlass*>* _local_interfaces;
292
// Interfaces (InstanceKlass*s) this class implements transitively.
293
Array<InstanceKlass*>* _transitive_interfaces;
294
// Int array containing the original order of method in the class file (for JVMTI).
295
Array<int>* _method_ordering;
296
// Int array containing the vtable_indices for default_methods
297
// offset matches _default_methods offset
298
Array<int>* _default_vtable_indices;
299
300
// Instance and static variable information, starts with 6-tuples of shorts
301
// [access, name index, sig index, initval index, low_offset, high_offset]
302
// for all fields, followed by the generic signature data at the end of
303
// the array. Only fields with generic signature attributes have the generic
304
// signature data set in the array. The fields array looks like following:
305
//
306
// f1: [access, name index, sig index, initial value index, low_offset, high_offset]
307
// f2: [access, name index, sig index, initial value index, low_offset, high_offset]
308
// ...
309
// fn: [access, name index, sig index, initial value index, low_offset, high_offset]
310
// [generic signature index]
311
// [generic signature index]
312
// ...
313
Array<u2>* _fields;
314
315
// embedded Java vtable follows here
316
// embedded Java itables follows here
317
// embedded static fields follows here
318
// embedded nonstatic oop-map blocks follows here
319
// embedded implementor of this interface follows here
320
// The embedded implementor only exists if the current klass is an
321
// interface. The possible values of the implementor fall into following
322
// three cases:
323
// NULL: no implementor.
324
// A Klass* that's not itself: one implementor.
325
// Itself: more than one implementors.
326
//
327
328
friend class SystemDictionary;
329
330
static bool _disable_method_binary_search;
331
332
public:
333
// The three BUILTIN class loader types
334
bool is_shared_boot_class() const {
335
return (_misc_flags & _misc_is_shared_boot_class) != 0;
336
}
337
bool is_shared_platform_class() const {
338
return (_misc_flags & _misc_is_shared_platform_class) != 0;
339
}
340
bool is_shared_app_class() const {
341
return (_misc_flags & _misc_is_shared_app_class) != 0;
342
}
343
// The UNREGISTERED class loader type
344
bool is_shared_unregistered_class() const {
345
return (_misc_flags & shared_loader_type_bits()) == 0;
346
}
347
348
// Check if the class can be shared in CDS
349
bool is_shareable() const;
350
351
void clear_shared_class_loader_type() {
352
_misc_flags &= ~shared_loader_type_bits();
353
}
354
355
bool shared_loading_failed() const {
356
return (_misc_flags & _misc_shared_loading_failed) != 0;
357
}
358
359
void set_shared_loading_failed() {
360
_misc_flags |= _misc_shared_loading_failed;
361
}
362
363
void clear_shared_loading_failed() {
364
_misc_flags &= ~_misc_shared_loading_failed;
365
}
366
367
void set_shared_class_loader_type(s2 loader_type);
368
369
void assign_class_loader_type();
370
371
bool has_nonstatic_fields() const {
372
return (_misc_flags & _misc_has_nonstatic_fields) != 0;
373
}
374
void set_has_nonstatic_fields(bool b) {
375
if (b) {
376
_misc_flags |= _misc_has_nonstatic_fields;
377
} else {
378
_misc_flags &= ~_misc_has_nonstatic_fields;
379
}
380
}
381
382
// field sizes
383
int nonstatic_field_size() const { return _nonstatic_field_size; }
384
void set_nonstatic_field_size(int size) { _nonstatic_field_size = size; }
385
386
int static_field_size() const { return _static_field_size; }
387
void set_static_field_size(int size) { _static_field_size = size; }
388
389
int static_oop_field_count() const { return (int)_static_oop_field_count; }
390
void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; }
391
392
// Java itable
393
int itable_length() const { return _itable_len; }
394
void set_itable_length(int len) { _itable_len = len; }
395
396
// array klasses
397
ObjArrayKlass* array_klasses() const { return _array_klasses; }
398
inline ObjArrayKlass* array_klasses_acquire() const; // load with acquire semantics
399
void set_array_klasses(ObjArrayKlass* k) { _array_klasses = k; }
400
inline void release_set_array_klasses(ObjArrayKlass* k); // store with release semantics
401
402
// methods
403
Array<Method*>* methods() const { return _methods; }
404
void set_methods(Array<Method*>* a) { _methods = a; }
405
Method* method_with_idnum(int idnum);
406
Method* method_with_orig_idnum(int idnum);
407
Method* method_with_orig_idnum(int idnum, int version);
408
409
// method ordering
410
Array<int>* method_ordering() const { return _method_ordering; }
411
void set_method_ordering(Array<int>* m) { _method_ordering = m; }
412
void copy_method_ordering(const intArray* m, TRAPS);
413
414
// default_methods
415
Array<Method*>* default_methods() const { return _default_methods; }
416
void set_default_methods(Array<Method*>* a) { _default_methods = a; }
417
418
// default method vtable_indices
419
Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
420
void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
421
Array<int>* create_new_default_vtable_indices(int len, TRAPS);
422
423
// interfaces
424
Array<InstanceKlass*>* local_interfaces() const { return _local_interfaces; }
425
void set_local_interfaces(Array<InstanceKlass*>* a) {
426
guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
427
_local_interfaces = a; }
428
429
Array<InstanceKlass*>* transitive_interfaces() const { return _transitive_interfaces; }
430
void set_transitive_interfaces(Array<InstanceKlass*>* a) {
431
guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
432
_transitive_interfaces = a;
433
}
434
435
private:
436
friend class fieldDescriptor;
437
FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
438
439
public:
440
int field_offset (int index) const { return field(index)->offset(); }
441
int field_access_flags(int index) const { return field(index)->access_flags(); }
442
Symbol* field_name (int index) const { return field(index)->name(constants()); }
443
Symbol* field_signature (int index) const { return field(index)->signature(constants()); }
444
445
// Number of Java declared fields
446
int java_fields_count() const { return (int)_java_fields_count; }
447
448
Array<u2>* fields() const { return _fields; }
449
void set_fields(Array<u2>* f, u2 java_fields_count) {
450
guarantee(_fields == NULL || f == NULL, "Just checking");
451
_fields = f;
452
_java_fields_count = java_fields_count;
453
}
454
455
// inner classes
456
Array<u2>* inner_classes() const { return _inner_classes; }
457
void set_inner_classes(Array<u2>* f) { _inner_classes = f; }
458
459
// nest members
460
Array<u2>* nest_members() const { return _nest_members; }
461
void set_nest_members(Array<u2>* m) { _nest_members = m; }
462
463
// nest-host index
464
jushort nest_host_index() const { return _nest_host_index; }
465
void set_nest_host_index(u2 i) { _nest_host_index = i; }
466
// dynamic nest member support
467
void set_nest_host(InstanceKlass* host);
468
469
// record components
470
Array<RecordComponent*>* record_components() const { return _record_components; }
471
void set_record_components(Array<RecordComponent*>* record_components) {
472
_record_components = record_components;
473
}
474
bool is_record() const;
475
476
// permitted subclasses
477
Array<u2>* permitted_subclasses() const { return _permitted_subclasses; }
478
void set_permitted_subclasses(Array<u2>* s) { _permitted_subclasses = s; }
479
480
private:
481
// Called to verify that k is a member of this nest - does not look at k's nest-host,
482
// nor does it resolve any CP entries or load any classes.
483
bool has_nest_member(JavaThread* current, InstanceKlass* k) const;
484
485
public:
486
// Used to construct informative IllegalAccessError messages at a higher level,
487
// if there was an issue resolving or validating the nest host.
488
// Returns NULL if there was no error.
489
const char* nest_host_error();
490
// Returns nest-host class, resolving and validating it if needed.
491
// Returns NULL if resolution is not possible from the calling context.
492
InstanceKlass* nest_host(TRAPS);
493
// Check if this klass is a nestmate of k - resolves this nest-host and k's
494
bool has_nestmate_access_to(InstanceKlass* k, TRAPS);
495
496
// Called to verify that k is a permitted subclass of this class
497
bool has_as_permitted_subclass(const InstanceKlass* k) const;
498
499
enum InnerClassAttributeOffset {
500
// From http://mirror.eng/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc10.html#18814
501
inner_class_inner_class_info_offset = 0,
502
inner_class_outer_class_info_offset = 1,
503
inner_class_inner_name_offset = 2,
504
inner_class_access_flags_offset = 3,
505
inner_class_next_offset = 4
506
};
507
508
enum EnclosingMethodAttributeOffset {
509
enclosing_method_class_index_offset = 0,
510
enclosing_method_method_index_offset = 1,
511
enclosing_method_attribute_size = 2
512
};
513
514
// package
515
PackageEntry* package() const { return _package_entry; }
516
ModuleEntry* module() const;
517
bool in_unnamed_package() const { return (_package_entry == NULL); }
518
void set_package(ClassLoaderData* loader_data, PackageEntry* pkg_entry, TRAPS);
519
// If the package for the InstanceKlass is in the boot loader's package entry
520
// table then sets the classpath_index field so that
521
// get_system_package() will know to return a non-null value for the
522
// package's location. And, so that the package will be added to the list of
523
// packages returned by get_system_packages().
524
// For packages whose classes are loaded from the boot loader class path, the
525
// classpath_index indicates which entry on the boot loader class path.
526
void set_classpath_index(s2 path_index);
527
bool is_same_class_package(const Klass* class2) const;
528
bool is_same_class_package(oop other_class_loader, const Symbol* other_class_name) const;
529
530
// find an enclosing class
531
InstanceKlass* compute_enclosing_class(bool* inner_is_member, TRAPS) const;
532
533
// Find InnerClasses attribute and return outer_class_info_index & inner_name_index.
534
bool find_inner_classes_attr(int* ooff, int* noff, TRAPS) const;
535
536
private:
537
// Check prohibited package ("java/" only loadable by boot or platform loaders)
538
static void check_prohibited_package(Symbol* class_name,
539
ClassLoaderData* loader_data,
540
TRAPS);
541
public:
542
// initialization state
543
bool is_loaded() const { return _init_state >= loaded; }
544
bool is_linked() const { return _init_state >= linked; }
545
bool is_initialized() const { return _init_state == fully_initialized; }
546
bool is_not_initialized() const { return _init_state < being_initialized; }
547
bool is_being_initialized() const { return _init_state == being_initialized; }
548
bool is_in_error_state() const { return _init_state == initialization_error; }
549
bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; }
550
ClassState init_state() { return (ClassState)_init_state; }
551
bool is_rewritten() const { return (_misc_flags & _misc_rewritten) != 0; }
552
553
// is this a sealed class
554
bool is_sealed() const;
555
556
// defineClass specified verification
557
bool should_verify_class() const {
558
return (_misc_flags & _misc_should_verify_class) != 0;
559
}
560
void set_should_verify_class(bool value) {
561
if (value) {
562
_misc_flags |= _misc_should_verify_class;
563
} else {
564
_misc_flags &= ~_misc_should_verify_class;
565
}
566
}
567
568
// marking
569
bool is_marked_dependent() const { return _is_marked_dependent; }
570
void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
571
572
// initialization (virtuals from Klass)
573
bool should_be_initialized() const; // means that initialize should be called
574
void initialize(TRAPS);
575
void link_class(TRAPS);
576
bool link_class_or_fail(TRAPS); // returns false on failure
577
void rewrite_class(TRAPS);
578
void link_methods(TRAPS);
579
Method* class_initializer() const;
580
581
// set the class to initialized if no static initializer is present
582
void eager_initialize(Thread *thread);
583
584
// reference type
585
ReferenceType reference_type() const { return (ReferenceType)_reference_type; }
586
void set_reference_type(ReferenceType t) {
587
assert(t == (u1)t, "overflow");
588
_reference_type = (u1)t;
589
}
590
591
// this class cp index
592
u2 this_class_index() const { return _this_class_index; }
593
void set_this_class_index(u2 index) { _this_class_index = index; }
594
595
static ByteSize reference_type_offset() { return in_ByteSize(offset_of(InstanceKlass, _reference_type)); }
596
597
// find local field, returns true if found
598
bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
599
// find field in direct superinterfaces, returns the interface in which the field is defined
600
Klass* find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
601
// find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
602
Klass* find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
603
// find instance or static fields according to JVM spec 5.4.3.2, returns the klass in which the field is defined
604
Klass* find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const;
605
606
// find a non-static or static field given its offset within the class.
607
bool contains_field_offset(int offset);
608
609
bool find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const;
610
bool find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const;
611
612
private:
613
inline static int quick_search(const Array<Method*>* methods, const Symbol* name);
614
615
public:
616
static void disable_method_binary_search() {
617
_disable_method_binary_search = true;
618
}
619
620
// find a local method (returns NULL if not found)
621
Method* find_method(const Symbol* name, const Symbol* signature) const;
622
static Method* find_method(const Array<Method*>* methods,
623
const Symbol* name,
624
const Symbol* signature);
625
626
// find a local method, but skip static methods
627
Method* find_instance_method(const Symbol* name, const Symbol* signature,
628
PrivateLookupMode private_mode) const;
629
static Method* find_instance_method(const Array<Method*>* methods,
630
const Symbol* name,
631
const Symbol* signature,
632
PrivateLookupMode private_mode);
633
634
// find a local method (returns NULL if not found)
635
Method* find_local_method(const Symbol* name,
636
const Symbol* signature,
637
OverpassLookupMode overpass_mode,
638
StaticLookupMode static_mode,
639
PrivateLookupMode private_mode) const;
640
641
// find a local method from given methods array (returns NULL if not found)
642
static Method* find_local_method(const Array<Method*>* methods,
643
const Symbol* name,
644
const Symbol* signature,
645
OverpassLookupMode overpass_mode,
646
StaticLookupMode static_mode,
647
PrivateLookupMode private_mode);
648
649
// find a local method index in methods or default_methods (returns -1 if not found)
650
static int find_method_index(const Array<Method*>* methods,
651
const Symbol* name,
652
const Symbol* signature,
653
OverpassLookupMode overpass_mode,
654
StaticLookupMode static_mode,
655
PrivateLookupMode private_mode);
656
657
// lookup operation (returns NULL if not found)
658
Method* uncached_lookup_method(const Symbol* name,
659
const Symbol* signature,
660
OverpassLookupMode overpass_mode,
661
PrivateLookupMode private_mode = PrivateLookupMode::find) const;
662
663
// lookup a method in all the interfaces that this class implements
664
// (returns NULL if not found)
665
Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature, DefaultsLookupMode defaults_mode) const;
666
667
// lookup a method in local defaults then in all interfaces
668
// (returns NULL if not found)
669
Method* lookup_method_in_ordered_interfaces(Symbol* name, Symbol* signature) const;
670
671
// Find method indices by name. If a method with the specified name is
672
// found the index to the first method is returned, and 'end' is filled in
673
// with the index of first non-name-matching method. If no method is found
674
// -1 is returned.
675
int find_method_by_name(const Symbol* name, int* end) const;
676
static int find_method_by_name(const Array<Method*>* methods,
677
const Symbol* name, int* end);
678
679
// constant pool
680
ConstantPool* constants() const { return _constants; }
681
void set_constants(ConstantPool* c) { _constants = c; }
682
683
// protection domain
684
oop protection_domain() const;
685
686
// signers
687
objArrayOop signers() const;
688
689
bool is_contended() const {
690
return (_misc_flags & _misc_is_contended) != 0;
691
}
692
void set_is_contended(bool value) {
693
if (value) {
694
_misc_flags |= _misc_is_contended;
695
} else {
696
_misc_flags &= ~_misc_is_contended;
697
}
698
}
699
700
// source file name
701
Symbol* source_file_name() const { return _constants->source_file_name(); }
702
u2 source_file_name_index() const { return _constants->source_file_name_index(); }
703
void set_source_file_name_index(u2 sourcefile_index) { _constants->set_source_file_name_index(sourcefile_index); }
704
705
// minor and major version numbers of class file
706
u2 minor_version() const { return _constants->minor_version(); }
707
void set_minor_version(u2 minor_version) { _constants->set_minor_version(minor_version); }
708
u2 major_version() const { return _constants->major_version(); }
709
void set_major_version(u2 major_version) { _constants->set_major_version(major_version); }
710
711
// source debug extension
712
const char* source_debug_extension() const { return _source_debug_extension; }
713
void set_source_debug_extension(const char* array, int length);
714
715
// nonstatic oop-map blocks
716
static int nonstatic_oop_map_size(unsigned int oop_map_count) {
717
return oop_map_count * OopMapBlock::size_in_words();
718
}
719
unsigned int nonstatic_oop_map_count() const {
720
return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
721
}
722
int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
723
void set_nonstatic_oop_map_size(int words) {
724
_nonstatic_oop_map_size = words;
725
}
726
727
bool has_contended_annotations() const {
728
return ((_misc_flags & _misc_has_contended_annotations) != 0);
729
}
730
void set_has_contended_annotations(bool value) {
731
if (value) {
732
_misc_flags |= _misc_has_contended_annotations;
733
} else {
734
_misc_flags &= ~_misc_has_contended_annotations;
735
}
736
}
737
738
#if INCLUDE_JVMTI
739
// Redefinition locking. Class can only be redefined by one thread at a time.
740
// The flag is in access_flags so that it can be set and reset using atomic
741
// operations, and not be reset by other misc_flag settings.
742
bool is_being_redefined() const {
743
return _access_flags.is_being_redefined();
744
}
745
void set_is_being_redefined(bool value) {
746
if (value) {
747
_access_flags.set_is_being_redefined();
748
} else {
749
_access_flags.clear_is_being_redefined();
750
}
751
}
752
753
// RedefineClasses() support for previous versions:
754
void add_previous_version(InstanceKlass* ik, int emcp_method_count);
755
void purge_previous_version_list();
756
757
InstanceKlass* previous_versions() const { return _previous_versions; }
758
#else
759
InstanceKlass* previous_versions() const { return NULL; }
760
#endif
761
762
InstanceKlass* get_klass_version(int version) {
763
for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) {
764
if (ik->constants()->version() == version) {
765
return ik;
766
}
767
}
768
return NULL;
769
}
770
771
bool has_been_redefined() const {
772
return (_misc_flags & _misc_has_been_redefined) != 0;
773
}
774
void set_has_been_redefined() {
775
_misc_flags |= _misc_has_been_redefined;
776
}
777
778
bool is_scratch_class() const {
779
return (_misc_flags & _misc_is_scratch_class) != 0;
780
}
781
782
void set_is_scratch_class() {
783
_misc_flags |= _misc_is_scratch_class;
784
}
785
786
bool has_resolved_methods() const {
787
return (_misc_flags & _misc_has_resolved_methods) != 0;
788
}
789
790
void set_has_resolved_methods() {
791
_misc_flags |= _misc_has_resolved_methods;
792
}
793
private:
794
795
void set_kind(unsigned kind) {
796
_kind = (u1)kind;
797
}
798
799
bool is_kind(unsigned desired) const {
800
return _kind == (u1)desired;
801
}
802
803
public:
804
805
// Other is anything that is not one of the more specialized kinds of InstanceKlass.
806
bool is_other_instance_klass() const { return is_kind(_kind_other); }
807
bool is_reference_instance_klass() const { return is_kind(_kind_reference); }
808
bool is_mirror_instance_klass() const { return is_kind(_kind_mirror); }
809
bool is_class_loader_instance_klass() const { return is_kind(_kind_class_loader); }
810
811
#if INCLUDE_JVMTI
812
813
void init_previous_versions() {
814
_previous_versions = NULL;
815
}
816
817
private:
818
static bool _has_previous_versions;
819
public:
820
static void purge_previous_versions(InstanceKlass* ik) {
821
if (ik->has_been_redefined()) {
822
ik->purge_previous_version_list();
823
}
824
}
825
826
static bool has_previous_versions_and_reset();
827
static bool has_previous_versions() { return _has_previous_versions; }
828
829
// JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
830
void set_cached_class_file(JvmtiCachedClassFileData *data) {
831
_cached_class_file = data;
832
}
833
JvmtiCachedClassFileData * get_cached_class_file();
834
jint get_cached_class_file_len();
835
unsigned char * get_cached_class_file_bytes();
836
837
// JVMTI: Support for caching of field indices, types, and offsets
838
void set_jvmti_cached_class_field_map(JvmtiCachedClassFieldMap* descriptor) {
839
_jvmti_cached_class_field_map = descriptor;
840
}
841
JvmtiCachedClassFieldMap* jvmti_cached_class_field_map() const {
842
return _jvmti_cached_class_field_map;
843
}
844
#else // INCLUDE_JVMTI
845
846
static void purge_previous_versions(InstanceKlass* ik) { return; };
847
static bool has_previous_versions_and_reset() { return false; }
848
849
void set_cached_class_file(JvmtiCachedClassFileData *data) {
850
assert(data == NULL, "unexpected call with JVMTI disabled");
851
}
852
JvmtiCachedClassFileData * get_cached_class_file() { return (JvmtiCachedClassFileData *)NULL; }
853
854
#endif // INCLUDE_JVMTI
855
856
bool has_nonstatic_concrete_methods() const {
857
return (_misc_flags & _misc_has_nonstatic_concrete_methods) != 0;
858
}
859
void set_has_nonstatic_concrete_methods(bool b) {
860
if (b) {
861
_misc_flags |= _misc_has_nonstatic_concrete_methods;
862
} else {
863
_misc_flags &= ~_misc_has_nonstatic_concrete_methods;
864
}
865
}
866
867
bool declares_nonstatic_concrete_methods() const {
868
return (_misc_flags & _misc_declares_nonstatic_concrete_methods) != 0;
869
}
870
void set_declares_nonstatic_concrete_methods(bool b) {
871
if (b) {
872
_misc_flags |= _misc_declares_nonstatic_concrete_methods;
873
} else {
874
_misc_flags &= ~_misc_declares_nonstatic_concrete_methods;
875
}
876
}
877
878
// for adding methods, ConstMethod::UNSET_IDNUM means no more ids available
879
inline u2 next_method_idnum();
880
void set_initial_method_idnum(u2 value) { _idnum_allocated_count = value; }
881
882
// generics support
883
Symbol* generic_signature() const { return _constants->generic_signature(); }
884
u2 generic_signature_index() const { return _constants->generic_signature_index(); }
885
void set_generic_signature_index(u2 sig_index) { _constants->set_generic_signature_index(sig_index); }
886
887
u2 enclosing_method_data(int offset) const;
888
u2 enclosing_method_class_index() const {
889
return enclosing_method_data(enclosing_method_class_index_offset);
890
}
891
u2 enclosing_method_method_index() {
892
return enclosing_method_data(enclosing_method_method_index_offset);
893
}
894
void set_enclosing_method_indices(u2 class_index,
895
u2 method_index);
896
897
// jmethodID support
898
jmethodID get_jmethod_id(const methodHandle& method_h);
899
jmethodID get_jmethod_id_fetch_or_update(size_t idnum,
900
jmethodID new_id, jmethodID* new_jmeths,
901
jmethodID* to_dealloc_id_p,
902
jmethodID** to_dealloc_jmeths_p);
903
static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
904
size_t *length_p, jmethodID* id_p);
905
void ensure_space_for_methodids(int start_offset = 0);
906
jmethodID jmethod_id_or_null(Method* method);
907
908
// annotations support
909
Annotations* annotations() const { return _annotations; }
910
void set_annotations(Annotations* anno) { _annotations = anno; }
911
912
AnnotationArray* class_annotations() const {
913
return (_annotations != NULL) ? _annotations->class_annotations() : NULL;
914
}
915
Array<AnnotationArray*>* fields_annotations() const {
916
return (_annotations != NULL) ? _annotations->fields_annotations() : NULL;
917
}
918
AnnotationArray* class_type_annotations() const {
919
return (_annotations != NULL) ? _annotations->class_type_annotations() : NULL;
920
}
921
Array<AnnotationArray*>* fields_type_annotations() const {
922
return (_annotations != NULL) ? _annotations->fields_type_annotations() : NULL;
923
}
924
// allocation
925
instanceOop allocate_instance(TRAPS);
926
static instanceOop allocate_instance(oop cls, TRAPS);
927
928
// additional member function to return a handle
929
instanceHandle allocate_instance_handle(TRAPS);
930
931
objArrayOop allocate_objArray(int n, int length, TRAPS);
932
// Helper function
933
static instanceOop register_finalizer(instanceOop i, TRAPS);
934
935
// Check whether reflection/jni/jvm code is allowed to instantiate this class;
936
// if not, throw either an Error or an Exception.
937
virtual void check_valid_for_instantiation(bool throwError, TRAPS);
938
939
// initialization
940
void call_class_initializer(TRAPS);
941
void set_initialization_state_and_notify(ClassState state, TRAPS);
942
943
// OopMapCache support
944
OopMapCache* oop_map_cache() { return _oop_map_cache; }
945
void set_oop_map_cache(OopMapCache *cache) { _oop_map_cache = cache; }
946
void mask_for(const methodHandle& method, int bci, InterpreterOopMap* entry);
947
948
// JNI identifier support (for static fields - for jni performance)
949
JNIid* jni_ids() { return _jni_ids; }
950
void set_jni_ids(JNIid* ids) { _jni_ids = ids; }
951
JNIid* jni_id_for(int offset);
952
953
// maintenance of deoptimization dependencies
954
inline DependencyContext dependencies();
955
int mark_dependent_nmethods(KlassDepChange& changes);
956
void add_dependent_nmethod(nmethod* nm);
957
void remove_dependent_nmethod(nmethod* nm);
958
void clean_dependency_context();
959
960
// On-stack replacement support
961
nmethod* osr_nmethods_head() const { return _osr_nmethods_head; };
962
void set_osr_nmethods_head(nmethod* h) { _osr_nmethods_head = h; };
963
void add_osr_nmethod(nmethod* n);
964
bool remove_osr_nmethod(nmethod* n);
965
int mark_osr_nmethods(const Method* m);
966
nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
967
968
#if INCLUDE_JVMTI
969
// Breakpoint support (see methods on Method* for details)
970
BreakpointInfo* breakpoints() const { return _breakpoints; };
971
void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
972
#endif
973
974
// support for stub routines
975
static ByteSize init_state_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
976
JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
977
static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
978
979
// subclass/subinterface checks
980
bool implements_interface(Klass* k) const;
981
bool is_same_or_direct_interface(Klass* k) const;
982
983
#ifdef ASSERT
984
// check whether this class or one of its superclasses was redefined
985
bool has_redefined_this_or_super() const;
986
#endif
987
988
// Access to the implementor of an interface.
989
InstanceKlass* implementor() const;
990
void set_implementor(InstanceKlass* ik);
991
int nof_implementors() const;
992
void add_implementor(InstanceKlass* ik); // ik is a new class that implements this interface
993
void init_implementor(); // initialize
994
995
// link this class into the implementors list of every interface it implements
996
void process_interfaces();
997
998
// virtual operations from Klass
999
GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
1000
Array<InstanceKlass*>* transitive_interfaces);
1001
bool can_be_primary_super_slow() const;
1002
int oop_size(oop obj) const { return size_helper(); }
1003
// slow because it's a virtual call and used for verifying the layout_helper.
1004
// Using the layout_helper bits, we can call is_instance_klass without a virtual call.
1005
DEBUG_ONLY(bool is_instance_klass_slow() const { return true; })
1006
1007
// Iterators
1008
void do_local_static_fields(FieldClosure* cl);
1009
void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
1010
void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
1011
1012
void methods_do(void f(Method* method));
1013
void array_klasses_do(void f(Klass* k));
1014
void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
1015
1016
static InstanceKlass* cast(Klass* k) {
1017
return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1018
}
1019
1020
static const InstanceKlass* cast(const Klass* k) {
1021
assert(k != NULL, "k should not be null");
1022
assert(k->is_instance_klass(), "cast to InstanceKlass");
1023
return static_cast<const InstanceKlass*>(k);
1024
}
1025
1026
virtual InstanceKlass* java_super() const {
1027
return (super() == NULL) ? NULL : cast(super());
1028
}
1029
1030
// Sizing (in words)
1031
static int header_size() { return sizeof(InstanceKlass)/wordSize; }
1032
1033
static int size(int vtable_length, int itable_length,
1034
int nonstatic_oop_map_size,
1035
bool is_interface) {
1036
return align_metadata_size(header_size() +
1037
vtable_length +
1038
itable_length +
1039
nonstatic_oop_map_size +
1040
(is_interface ? (int)sizeof(Klass*)/wordSize : 0));
1041
}
1042
1043
int size() const { return size(vtable_length(),
1044
itable_length(),
1045
nonstatic_oop_map_size(),
1046
is_interface());
1047
}
1048
1049
1050
inline intptr_t* start_of_itable() const;
1051
inline intptr_t* end_of_itable() const;
1052
inline int itable_offset_in_words() const;
1053
inline oop static_field_base_raw();
1054
1055
inline OopMapBlock* start_of_nonstatic_oop_maps() const;
1056
inline Klass** end_of_nonstatic_oop_maps() const;
1057
1058
inline InstanceKlass* volatile* adr_implementor() const;
1059
1060
// Use this to return the size of an instance in heap words:
1061
int size_helper() const {
1062
return layout_helper_to_size_helper(layout_helper());
1063
}
1064
1065
// This bit is initialized in classFileParser.cpp.
1066
// It is false under any of the following conditions:
1067
// - the class is abstract (including any interface)
1068
// - the class has a finalizer (if !RegisterFinalizersAtInit)
1069
// - the class size is larger than FastAllocateSizeLimit
1070
// - the class is java/lang/Class, which cannot be allocated directly
1071
bool can_be_fastpath_allocated() const {
1072
return !layout_helper_needs_slow_path(layout_helper());
1073
}
1074
1075
// Java itable
1076
klassItable itable() const; // return klassItable wrapper
1077
Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
1078
Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
1079
int vtable_index_of_interface_method(Method* method);
1080
1081
#if INCLUDE_JVMTI
1082
void adjust_default_methods(bool* trace_name_printed);
1083
#endif // INCLUDE_JVMTI
1084
1085
void clean_weak_instanceklass_links();
1086
private:
1087
void clean_implementors_list();
1088
void clean_method_data();
1089
1090
public:
1091
// Explicit metaspace deallocation of fields
1092
// For RedefineClasses and class file parsing errors, we need to deallocate
1093
// instanceKlasses and the metadata they point to.
1094
void deallocate_contents(ClassLoaderData* loader_data);
1095
static void deallocate_methods(ClassLoaderData* loader_data,
1096
Array<Method*>* methods);
1097
void static deallocate_interfaces(ClassLoaderData* loader_data,
1098
const Klass* super_klass,
1099
Array<InstanceKlass*>* local_interfaces,
1100
Array<InstanceKlass*>* transitive_interfaces);
1101
void static deallocate_record_components(ClassLoaderData* loader_data,
1102
Array<RecordComponent*>* record_component);
1103
1104
// The constant pool is on stack if any of the methods are executing or
1105
// referenced by handles.
1106
bool on_stack() const { return _constants->on_stack(); }
1107
1108
// callbacks for actions during class unloading
1109
static void unload_class(InstanceKlass* ik);
1110
1111
virtual void release_C_heap_structures(bool release_constant_pool = true);
1112
1113
// Naming
1114
const char* signature_name() const;
1115
1116
// Oop fields (and metadata) iterators
1117
//
1118
// The InstanceKlass iterators also visits the Object's klass.
1119
1120
// Forward iteration
1121
public:
1122
// Iterate over all oop fields in the oop maps.
1123
template <typename T, class OopClosureType>
1124
inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1125
1126
// Iterate over all oop fields and metadata.
1127
template <typename T, class OopClosureType>
1128
inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1129
1130
// Iterate over all oop fields in one oop map.
1131
template <typename T, class OopClosureType>
1132
inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1133
1134
1135
// Reverse iteration
1136
// Iterate over all oop fields and metadata.
1137
template <typename T, class OopClosureType>
1138
inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure);
1139
1140
private:
1141
// Iterate over all oop fields in the oop maps.
1142
template <typename T, class OopClosureType>
1143
inline void oop_oop_iterate_oop_maps_reverse(oop obj, OopClosureType* closure);
1144
1145
// Iterate over all oop fields in one oop map.
1146
template <typename T, class OopClosureType>
1147
inline void oop_oop_iterate_oop_map_reverse(OopMapBlock* map, oop obj, OopClosureType* closure);
1148
1149
1150
// Bounded range iteration
1151
public:
1152
// Iterate over all oop fields in the oop maps.
1153
template <typename T, class OopClosureType>
1154
inline void oop_oop_iterate_oop_maps_bounded(oop obj, OopClosureType* closure, MemRegion mr);
1155
1156
// Iterate over all oop fields and metadata.
1157
template <typename T, class OopClosureType>
1158
inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
1159
1160
private:
1161
// Iterate over all oop fields in one oop map.
1162
template <typename T, class OopClosureType>
1163
inline void oop_oop_iterate_oop_map_bounded(OopMapBlock* map, oop obj, OopClosureType* closure, MemRegion mr);
1164
1165
1166
public:
1167
u2 idnum_allocated_count() const { return _idnum_allocated_count; }
1168
1169
private:
1170
// initialization state
1171
void set_init_state(ClassState state);
1172
void set_rewritten() { _misc_flags |= _misc_rewritten; }
1173
void set_init_thread(Thread *thread) { _init_thread = thread; }
1174
1175
// The RedefineClasses() API can cause new method idnums to be needed
1176
// which will cause the caches to grow. Safety requires different
1177
// cache management logic if the caches can grow instead of just
1178
// going from NULL to non-NULL.
1179
bool idnum_can_increment() const { return has_been_redefined(); }
1180
inline jmethodID* methods_jmethod_ids_acquire() const;
1181
inline void release_set_methods_jmethod_ids(jmethodID* jmeths);
1182
1183
// Lock during initialization
1184
public:
1185
// Lock for (1) initialization; (2) access to the ConstantPool of this class.
1186
// Must be one per class and it has to be a VM internal object so java code
1187
// cannot lock it (like the mirror).
1188
// It has to be an object not a Mutex because it's held through java calls.
1189
oop init_lock() const;
1190
1191
// Returns the array class for the n'th dimension
1192
virtual Klass* array_klass(int n, TRAPS);
1193
virtual Klass* array_klass_or_null(int n);
1194
1195
// Returns the array class with this class as element type
1196
virtual Klass* array_klass(TRAPS);
1197
virtual Klass* array_klass_or_null();
1198
1199
private:
1200
void fence_and_clear_init_lock();
1201
1202
bool link_class_impl (TRAPS);
1203
bool verify_code (TRAPS);
1204
void initialize_impl (TRAPS);
1205
void initialize_super_interfaces (TRAPS);
1206
void eager_initialize_impl ();
1207
1208
// find a local method (returns NULL if not found)
1209
Method* find_method_impl(const Symbol* name,
1210
const Symbol* signature,
1211
OverpassLookupMode overpass_mode,
1212
StaticLookupMode static_mode,
1213
PrivateLookupMode private_mode) const;
1214
1215
static Method* find_method_impl(const Array<Method*>* methods,
1216
const Symbol* name,
1217
const Symbol* signature,
1218
OverpassLookupMode overpass_mode,
1219
StaticLookupMode static_mode,
1220
PrivateLookupMode private_mode);
1221
1222
#if INCLUDE_JVMTI
1223
// RedefineClasses support
1224
void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
1225
void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1226
#endif
1227
// log class name to classlist
1228
void log_to_classlist() const;
1229
public:
1230
// CDS support - remove and restore oops from metadata. Oops are not shared.
1231
virtual void remove_unshareable_info();
1232
virtual void remove_java_mirror();
1233
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
1234
void init_shared_package_entry();
1235
bool can_be_verified_at_dumptime() const;
1236
1237
jint compute_modifier_flags() const;
1238
1239
public:
1240
// JVMTI support
1241
jint jvmti_class_status() const;
1242
1243
virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1244
1245
public:
1246
// Printing
1247
void print_on(outputStream* st) const;
1248
void print_value_on(outputStream* st) const;
1249
1250
void oop_print_value_on(oop obj, outputStream* st);
1251
1252
void oop_print_on (oop obj, outputStream* st);
1253
1254
#ifndef PRODUCT
1255
void print_dependent_nmethods(bool verbose = false);
1256
bool is_dependent_nmethod(nmethod* nm);
1257
bool verify_itable_index(int index);
1258
#endif
1259
1260
const char* internal_name() const;
1261
1262
// Verification
1263
void verify_on(outputStream* st);
1264
1265
void oop_verify_on(oop obj, outputStream* st);
1266
1267
// Logging
1268
void print_class_load_logging(ClassLoaderData* loader_data,
1269
const ModuleEntry* module_entry,
1270
const ClassFileStream* cfs) const;
1271
};
1272
1273
// for adding methods
1274
// UNSET_IDNUM return means no more ids available
1275
inline u2 InstanceKlass::next_method_idnum() {
1276
if (_idnum_allocated_count == ConstMethod::MAX_IDNUM) {
1277
return ConstMethod::UNSET_IDNUM; // no more ids available
1278
} else {
1279
return _idnum_allocated_count++;
1280
}
1281
}
1282
1283
1284
/* JNIid class for jfieldIDs only */
1285
class JNIid: public CHeapObj<mtClass> {
1286
friend class VMStructs;
1287
private:
1288
Klass* _holder;
1289
JNIid* _next;
1290
int _offset;
1291
#ifdef ASSERT
1292
bool _is_static_field_id;
1293
#endif
1294
1295
public:
1296
// Accessors
1297
Klass* holder() const { return _holder; }
1298
int offset() const { return _offset; }
1299
JNIid* next() { return _next; }
1300
// Constructor
1301
JNIid(Klass* holder, int offset, JNIid* next);
1302
// Identifier lookup
1303
JNIid* find(int offset);
1304
1305
bool find_local_field(fieldDescriptor* fd) {
1306
return InstanceKlass::cast(holder())->find_local_field_from_offset(offset(), true, fd);
1307
}
1308
1309
static void deallocate(JNIid* id);
1310
// Debugging
1311
#ifdef ASSERT
1312
bool is_static_field_id() const { return _is_static_field_id; }
1313
void set_is_static_field_id() { _is_static_field_id = true; }
1314
#endif
1315
void verify(Klass* holder);
1316
};
1317
1318
// An iterator that's used to access the inner classes indices in the
1319
// InstanceKlass::_inner_classes array.
1320
class InnerClassesIterator : public StackObj {
1321
private:
1322
Array<jushort>* _inner_classes;
1323
int _length;
1324
int _idx;
1325
public:
1326
1327
InnerClassesIterator(const InstanceKlass* k) {
1328
_inner_classes = k->inner_classes();
1329
if (k->inner_classes() != NULL) {
1330
_length = _inner_classes->length();
1331
// The inner class array's length should be the multiple of
1332
// inner_class_next_offset if it only contains the InnerClasses
1333
// attribute data, or it should be
1334
// n*inner_class_next_offset+enclosing_method_attribute_size
1335
// if it also contains the EnclosingMethod data.
1336
assert((_length % InstanceKlass::inner_class_next_offset == 0 ||
1337
_length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size),
1338
"just checking");
1339
// Remove the enclosing_method portion if exists.
1340
if (_length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size) {
1341
_length -= InstanceKlass::enclosing_method_attribute_size;
1342
}
1343
} else {
1344
_length = 0;
1345
}
1346
_idx = 0;
1347
}
1348
1349
int length() const {
1350
return _length;
1351
}
1352
1353
void next() {
1354
_idx += InstanceKlass::inner_class_next_offset;
1355
}
1356
1357
bool done() const {
1358
return (_idx >= _length);
1359
}
1360
1361
u2 inner_class_info_index() const {
1362
return _inner_classes->at(
1363
_idx + InstanceKlass::inner_class_inner_class_info_offset);
1364
}
1365
1366
void set_inner_class_info_index(u2 index) {
1367
_inner_classes->at_put(
1368
_idx + InstanceKlass::inner_class_inner_class_info_offset, index);
1369
}
1370
1371
u2 outer_class_info_index() const {
1372
return _inner_classes->at(
1373
_idx + InstanceKlass::inner_class_outer_class_info_offset);
1374
}
1375
1376
void set_outer_class_info_index(u2 index) {
1377
_inner_classes->at_put(
1378
_idx + InstanceKlass::inner_class_outer_class_info_offset, index);
1379
}
1380
1381
u2 inner_name_index() const {
1382
return _inner_classes->at(
1383
_idx + InstanceKlass::inner_class_inner_name_offset);
1384
}
1385
1386
void set_inner_name_index(u2 index) {
1387
_inner_classes->at_put(
1388
_idx + InstanceKlass::inner_class_inner_name_offset, index);
1389
}
1390
1391
u2 inner_access_flags() const {
1392
return _inner_classes->at(
1393
_idx + InstanceKlass::inner_class_access_flags_offset);
1394
}
1395
};
1396
1397
// Iterator over class hierarchy under a particular class. Implements depth-first pre-order traversal.
1398
// Usage:
1399
// for (ClassHierarchyIterator iter(root_klass); !iter.done(); iter.next()) {
1400
// Klass* k = iter.klass();
1401
// ...
1402
// }
1403
class ClassHierarchyIterator : public StackObj {
1404
private:
1405
InstanceKlass* _root;
1406
Klass* _current;
1407
bool _visit_subclasses;
1408
1409
public:
1410
ClassHierarchyIterator(InstanceKlass* root) : _root(root), _current(root), _visit_subclasses(true) {
1411
assert(_root == _current, "required"); // initial state
1412
}
1413
1414
bool done() {
1415
return (_current == NULL);
1416
}
1417
1418
// Make a step iterating over the class hierarchy under the root class.
1419
// Skips subclasses if requested.
1420
void next();
1421
1422
Klass* klass() {
1423
assert(!done(), "sanity");
1424
return _current;
1425
}
1426
1427
// Skip subclasses of the current class.
1428
void skip_subclasses() {
1429
_visit_subclasses = false;
1430
}
1431
};
1432
1433
#endif // SHARE_OOPS_INSTANCEKLASS_HPP
1434
1435