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