1 /*
2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
526 TRAPS);
527
528 JavaThread* init_thread() { return AtomicAccess::load(&_init_thread); }
529 const char* init_thread_name() {
530 return init_thread()->name_raw();
531 }
532
533 public:
534 // initialization state
535 bool is_loaded() const { return init_state() >= loaded; }
536 bool is_linked() const { return init_state() >= linked; }
537 bool is_initialized() const { return init_state() == fully_initialized; }
538 bool is_not_initialized() const { return init_state() < being_initialized; }
539 bool is_being_initialized() const { return init_state() == being_initialized; }
540 bool is_in_error_state() const { return init_state() == initialization_error; }
541 bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; }
542 ClassState init_state() const { return AtomicAccess::load_acquire(&_init_state); }
543 const char* init_state_name() const;
544 bool is_rewritten() const { return _misc_flags.rewritten(); }
545
546 // is this a sealed class
547 bool is_sealed() const;
548
549 // defineClass specified verification
550 bool should_verify_class() const { return _misc_flags.should_verify_class(); }
551 void set_should_verify_class(bool value) { _misc_flags.set_should_verify_class(value); }
552
553 // marking
554 bool is_marked_dependent() const { return _misc_flags.is_marked_dependent(); }
555 void set_is_marked_dependent(bool value) { _misc_flags.set_is_marked_dependent(value); }
556
557 // initialization (virtuals from Klass)
558 bool should_be_initialized() const override; // means that initialize should be called
559 void initialize_with_aot_initialized_mirror(TRAPS);
560 void assert_no_clinit_will_run_for_aot_initialized_class() const NOT_DEBUG_RETURN;
561 void initialize(TRAPS) override;
562 void initialize_preemptable(TRAPS) override;
563 void link_class(TRAPS);
564 bool link_class_or_fail(TRAPS); // returns false on failure
565 void rewrite_class(TRAPS);
566 void link_methods(TRAPS);
567 Method* class_initializer() const;
568 bool interface_needs_clinit_execution_as_super(bool also_check_supers=true) const;
569
570 // reference type
571 ReferenceType reference_type() const { return (ReferenceType)_reference_type; }
572
573 // this class cp index
574 u2 this_class_index() const { return _this_class_index; }
575 void set_this_class_index(u2 index) { _this_class_index = index; }
576
577 static ByteSize reference_type_offset() { return byte_offset_of(InstanceKlass, _reference_type); }
578
579 // find local field, returns true if found
810 void update_methods_jmethod_cache();
811
812 // annotations support
813 Annotations* annotations() const { return _annotations; }
814 void set_annotations(Annotations* anno) { _annotations = anno; }
815
816 AnnotationArray* class_annotations() const {
817 return (_annotations != nullptr) ? _annotations->class_annotations() : nullptr;
818 }
819 Array<AnnotationArray*>* fields_annotations() const {
820 return (_annotations != nullptr) ? _annotations->fields_annotations() : nullptr;
821 }
822 AnnotationArray* class_type_annotations() const {
823 return (_annotations != nullptr) ? _annotations->class_type_annotations() : nullptr;
824 }
825 Array<AnnotationArray*>* fields_type_annotations() const {
826 return (_annotations != nullptr) ? _annotations->fields_type_annotations() : nullptr;
827 }
828 // allocation
829 instanceOop allocate_instance(TRAPS);
830 static instanceOop allocate_instance(oop cls, TRAPS);
831
832 // additional member function to return a handle
833 instanceHandle allocate_instance_handle(TRAPS);
834
835 // Helper function
836 static instanceOop register_finalizer(instanceOop i, TRAPS);
837
838 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
839 // if not, throw either an Error or an Exception.
840 void check_valid_for_instantiation(bool throwError, TRAPS) override;
841
842 // initialization
843 void call_class_initializer(TRAPS);
844 void set_initialization_state_and_notify(ClassState state, TRAPS);
845
846 // OopMapCache support
847 OopMapCache* oop_map_cache() { return _oop_map_cache; }
848 void set_oop_map_cache(OopMapCache *cache) { _oop_map_cache = cache; }
849 void mask_for(const methodHandle& method, int bci, InterpreterOopMap* entry);
850
|
1 /*
2 * Copyright (c) 1997, 2026, 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 *
526 TRAPS);
527
528 JavaThread* init_thread() { return AtomicAccess::load(&_init_thread); }
529 const char* init_thread_name() {
530 return init_thread()->name_raw();
531 }
532
533 public:
534 // initialization state
535 bool is_loaded() const { return init_state() >= loaded; }
536 bool is_linked() const { return init_state() >= linked; }
537 bool is_initialized() const { return init_state() == fully_initialized; }
538 bool is_not_initialized() const { return init_state() < being_initialized; }
539 bool is_being_initialized() const { return init_state() == being_initialized; }
540 bool is_in_error_state() const { return init_state() == initialization_error; }
541 bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; }
542 ClassState init_state() const { return AtomicAccess::load_acquire(&_init_state); }
543 const char* init_state_name() const;
544 bool is_rewritten() const { return _misc_flags.rewritten(); }
545
546 static const char* state2name(ClassState state);
547
548 // is this a sealed class
549 bool is_sealed() const;
550
551 // defineClass specified verification
552 bool should_verify_class() const { return _misc_flags.should_verify_class(); }
553 void set_should_verify_class(bool value) { _misc_flags.set_should_verify_class(value); }
554
555 // marking
556 bool is_marked_dependent() const { return _misc_flags.is_marked_dependent(); }
557 void set_is_marked_dependent(bool value) { _misc_flags.set_is_marked_dependent(value); }
558
559 // initialization (virtuals from Klass)
560 bool should_be_initialized() const override; // means that initialize should be called
561 void initialize_with_aot_initialized_mirror(bool early_init, TRAPS);
562 void assert_no_clinit_will_run_for_aot_initialized_class() const NOT_DEBUG_RETURN;
563 void initialize(TRAPS) override;
564 void initialize_preemptable(TRAPS) override;
565 void link_class(TRAPS);
566 bool link_class_or_fail(TRAPS); // returns false on failure
567 void rewrite_class(TRAPS);
568 void link_methods(TRAPS);
569 Method* class_initializer() const;
570 bool interface_needs_clinit_execution_as_super(bool also_check_supers=true) const;
571
572 // reference type
573 ReferenceType reference_type() const { return (ReferenceType)_reference_type; }
574
575 // this class cp index
576 u2 this_class_index() const { return _this_class_index; }
577 void set_this_class_index(u2 index) { _this_class_index = index; }
578
579 static ByteSize reference_type_offset() { return byte_offset_of(InstanceKlass, _reference_type); }
580
581 // find local field, returns true if found
812 void update_methods_jmethod_cache();
813
814 // annotations support
815 Annotations* annotations() const { return _annotations; }
816 void set_annotations(Annotations* anno) { _annotations = anno; }
817
818 AnnotationArray* class_annotations() const {
819 return (_annotations != nullptr) ? _annotations->class_annotations() : nullptr;
820 }
821 Array<AnnotationArray*>* fields_annotations() const {
822 return (_annotations != nullptr) ? _annotations->fields_annotations() : nullptr;
823 }
824 AnnotationArray* class_type_annotations() const {
825 return (_annotations != nullptr) ? _annotations->class_type_annotations() : nullptr;
826 }
827 Array<AnnotationArray*>* fields_type_annotations() const {
828 return (_annotations != nullptr) ? _annotations->fields_type_annotations() : nullptr;
829 }
830 // allocation
831 instanceOop allocate_instance(TRAPS);
832 static instanceOop allocate_instance(oop cls, const char* who, TRAPS);
833
834 // additional member function to return a handle
835 instanceHandle allocate_instance_handle(TRAPS);
836
837 // Helper function
838 static instanceOop register_finalizer(instanceOop i, TRAPS);
839
840 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
841 // if not, throw either an Error or an Exception.
842 void check_valid_for_instantiation(bool throwError, TRAPS) override;
843
844 // initialization
845 void call_class_initializer(TRAPS);
846 void set_initialization_state_and_notify(ClassState state, TRAPS);
847
848 // OopMapCache support
849 OopMapCache* oop_map_cache() { return _oop_map_cache; }
850 void set_oop_map_cache(OopMapCache *cache) { _oop_map_cache = cache; }
851 void mask_for(const methodHandle& method, int bci, InterpreterOopMap* entry);
852
|