Path: blob/master/src/hotspot/share/memory/universe.hpp
40950 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_MEMORY_UNIVERSE_HPP25#define SHARE_MEMORY_UNIVERSE_HPP2627#include "gc/shared/verifyOption.hpp"28#include "oops/array.hpp"29#include "oops/oopHandle.hpp"30#include "runtime/handles.hpp"31#include "utilities/growableArray.hpp"3233// Universe is a name space holding known system classes and objects in the VM.34//35// Loaded classes are accessible through the SystemDictionary.36//37// The object heap is allocated and accessed through Universe, and various allocation38// support is provided. Allocation by the interpreter and compiled code is done inline39// and bails out to Scavenge::invoke_and_allocate.4041class CollectedHeap;42class DeferredObjAllocEvent;43class OopStorage;44class ReservedHeapSpace;4546// A helper class for caching a Method* when the user of the cache47// only cares about the latest version of the Method*. This cache safely48// interacts with the RedefineClasses API.4950class LatestMethodCache : public CHeapObj<mtClass> {51// We save the Klass* and the idnum of Method* in order to get52// the current cached Method*.53private:54Klass* _klass;55int _method_idnum;5657public:58LatestMethodCache() { _klass = NULL; _method_idnum = -1; }59~LatestMethodCache() { _klass = NULL; _method_idnum = -1; }6061void init(Klass* k, Method* m);62Klass* klass() const { return _klass; }63int method_idnum() const { return _method_idnum; }6465Method* get_method();6667// CDS support. Replace the klass in this with the archive version68// could use this for Enhanced Class Redefinition also.69void serialize(SerializeClosure* f) {70f->do_ptr((void**)&_klass);71}72void metaspace_pointers_do(MetaspaceClosure* it);73};7475class Universe: AllStatic {76// Ugh. Universe is much too friendly.77friend class MarkSweep;78friend class oopDesc;79friend class ClassLoader;80friend class SystemDictionary;81friend class ReservedHeapSpace;82friend class VMStructs;83friend class VM_PopulateDumpSharedSpace;84friend class Metaspace;85friend class MetaspaceShared;86friend class vmClasses;8788friend jint universe_init();89friend void universe2_init();90friend bool universe_post_init();91friend void universe_post_module_init();9293private:94// Known classes in the VM95static Klass* _typeArrayKlassObjs[T_LONG+1];96static Klass* _objectArrayKlassObj;9798// Known objects in the VM99static OopHandle _main_thread_group; // Reference to the main thread group object100static OopHandle _system_thread_group; // Reference to the system thread group object101102static OopHandle _the_empty_class_array; // Canonicalized obj array of type java.lang.Class103static OopHandle _the_null_string; // A cache of "null" as a Java string104static OopHandle _the_min_jint_string; // A cache of "-2147483648" as a Java string105106static OopHandle _the_null_sentinel; // A unique object pointer unused except as a sentinel for null.107108// preallocated error objects (no backtrace)109static OopHandle _out_of_memory_errors;110111// preallocated cause message for delayed StackOverflowError112static OopHandle _delayed_stack_overflow_error_message;113114static LatestMethodCache* _finalizer_register_cache; // static method for registering finalizable objects115static LatestMethodCache* _loader_addClass_cache; // method for registering loaded classes in class loader vector116static LatestMethodCache* _throw_illegal_access_error_cache; // Unsafe.throwIllegalAccessError() method117static LatestMethodCache* _throw_no_such_method_error_cache; // Unsafe.throwNoSuchMethodError() method118static LatestMethodCache* _do_stack_walk_cache; // method for stack walker callback119120static Array<int>* _the_empty_int_array; // Canonicalized int array121static Array<u2>* _the_empty_short_array; // Canonicalized short array122static Array<Klass*>* _the_empty_klass_array; // Canonicalized klass array123static Array<InstanceKlass*>* _the_empty_instance_klass_array; // Canonicalized instance klass array124static Array<Method*>* _the_empty_method_array; // Canonicalized method array125126static Array<Klass*>* _the_array_interfaces_array;127128// array of preallocated error objects with backtrace129static OopHandle _preallocated_out_of_memory_error_array;130131// number of preallocated error objects available for use132static volatile jint _preallocated_out_of_memory_error_avail_count;133134static OopHandle _null_ptr_exception_instance; // preallocated exception object135static OopHandle _arithmetic_exception_instance; // preallocated exception object136static OopHandle _virtual_machine_error_instance; // preallocated exception object137138// References waiting to be transferred to the ReferenceHandler139static OopHandle _reference_pending_list;140141// The particular choice of collected heap.142static CollectedHeap* _collectedHeap;143144static intptr_t _non_oop_bits;145146// array of dummy objects used with +FullGCAlot147debug_only(static OopHandle _fullgc_alot_dummy_array;)148debug_only(static int _fullgc_alot_dummy_next;)149150// Compiler/dispatch support151static int _base_vtable_size; // Java vtbl size of klass Object (in words)152153// Initialization154static bool _bootstrapping; // true during genesis155static bool _module_initialized; // true after call_initPhase2 called156static bool _fully_initialized; // true after universe_init and initialize_vtables called157158// the array of preallocated errors with backtraces159static objArrayOop preallocated_out_of_memory_errors();160161static objArrayOop out_of_memory_errors();162// generate an out of memory error; if possible using an error with preallocated backtrace;163// otherwise return the given default error.164static oop gen_out_of_memory_error(oop default_err);165166static OopStorage* _vm_weak;167static OopStorage* _vm_global;168169static jint initialize_heap();170static void initialize_tlab();171static void initialize_basic_type_mirrors(TRAPS);172static void fixup_mirrors(TRAPS);173174static void compute_base_vtable_size(); // compute vtable size of class Object175176static void genesis(TRAPS); // Create the initial world177178// Mirrors for primitive classes (created eagerly)179static oop check_mirror(oop m) {180assert(m != NULL, "mirror not initialized");181return m;182}183184// Debugging185static int _verify_count; // number of verifies done186187// True during call to verify(). Should only be set/cleared in verify().188static bool _verify_in_progress;189static long verify_flags;190191static uintptr_t _verify_oop_mask;192static uintptr_t _verify_oop_bits;193194public:195static void calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) PRODUCT_RETURN;196197// Known classes in the VM198static Klass* boolArrayKlassObj() { return typeArrayKlassObj(T_BOOLEAN); }199static Klass* byteArrayKlassObj() { return typeArrayKlassObj(T_BYTE); }200static Klass* charArrayKlassObj() { return typeArrayKlassObj(T_CHAR); }201static Klass* intArrayKlassObj() { return typeArrayKlassObj(T_INT); }202static Klass* shortArrayKlassObj() { return typeArrayKlassObj(T_SHORT); }203static Klass* longArrayKlassObj() { return typeArrayKlassObj(T_LONG); }204static Klass* floatArrayKlassObj() { return typeArrayKlassObj(T_FLOAT); }205static Klass* doubleArrayKlassObj() { return typeArrayKlassObj(T_DOUBLE); }206207static Klass* objectArrayKlassObj() { return _objectArrayKlassObj; }208209static Klass* typeArrayKlassObj(BasicType t) {210assert((uint)t >= T_BOOLEAN, "range check for type: %s", type2name(t));211assert((uint)t < T_LONG+1, "range check for type: %s", type2name(t));212assert(_typeArrayKlassObjs[t] != NULL, "domain check");213return _typeArrayKlassObjs[t];214}215216// Known objects in the VM217static oop int_mirror();218static oop float_mirror();219static oop double_mirror();220static oop byte_mirror();221static oop bool_mirror();222static oop char_mirror();223static oop long_mirror();224static oop short_mirror();225static oop void_mirror();226227// Table of primitive type mirrors, excluding T_OBJECT and T_ARRAY228// but including T_VOID, hence the index including T_VOID229static OopHandle _mirrors[T_VOID+1];230231static oop java_mirror(BasicType t);232static void replace_mirror(BasicType t, oop obj);233234static oop main_thread_group();235static void set_main_thread_group(oop group);236237static oop system_thread_group();238static void set_system_thread_group(oop group);239240static objArrayOop the_empty_class_array ();241242static oop the_null_string();243static oop the_min_jint_string();244245static oop null_ptr_exception_instance();246static oop arithmetic_exception_instance();247static oop virtual_machine_error_instance();248static oop vm_exception() { return virtual_machine_error_instance(); }249250static Array<Klass*>* the_array_interfaces_array() { return _the_array_interfaces_array; }251static Method* finalizer_register_method() { return _finalizer_register_cache->get_method(); }252static Method* loader_addClass_method() { return _loader_addClass_cache->get_method(); }253254static Method* throw_illegal_access_error() { return _throw_illegal_access_error_cache->get_method(); }255static Method* throw_no_such_method_error() { return _throw_no_such_method_error_cache->get_method(); }256257static Method* do_stack_walk_method() { return _do_stack_walk_cache->get_method(); }258259static oop the_null_sentinel();260static address the_null_sentinel_addr() { return (address) &_the_null_sentinel; }261262// Function to initialize these263static void initialize_known_methods(TRAPS);264265static void create_preallocated_out_of_memory_errors(TRAPS);266267// Reference pending list manipulation. Access is protected by268// Heap_lock. The getter, setter and predicate require the caller269// owns the lock. Swap is used by parallel non-concurrent reference270// processing threads, where some higher level controller owns271// Heap_lock, so requires the lock is locked, but not necessarily by272// the current thread.273static oop reference_pending_list();274static void clear_reference_pending_list();275static bool has_reference_pending_list();276static oop swap_reference_pending_list(oop list);277278static Array<int>* the_empty_int_array() { return _the_empty_int_array; }279static Array<u2>* the_empty_short_array() { return _the_empty_short_array; }280static Array<Method*>* the_empty_method_array() { return _the_empty_method_array; }281static Array<Klass*>* the_empty_klass_array() { return _the_empty_klass_array; }282static Array<InstanceKlass*>* the_empty_instance_klass_array() { return _the_empty_instance_klass_array; }283284// OutOfMemoryError support. Returns an error with the required message. The returned error285// may or may not have a backtrace. If error has a backtrace then the stack trace is already286// filled in.287static oop out_of_memory_error_java_heap();288static oop out_of_memory_error_c_heap();289static oop out_of_memory_error_metaspace();290static oop out_of_memory_error_class_metaspace();291static oop out_of_memory_error_array_size();292static oop out_of_memory_error_gc_overhead_limit();293static oop out_of_memory_error_realloc_objects();294295// Throw default _out_of_memory_error_retry object as it will never propagate out of the VM296static oop out_of_memory_error_retry();297static oop delayed_stack_overflow_error_message();298299// The particular choice of collected heap.300static CollectedHeap* heap() { return _collectedHeap; }301302DEBUG_ONLY(static bool is_gc_active();)303DEBUG_ONLY(static bool is_in_heap(const void* p);)304DEBUG_ONLY(static bool is_in_heap_or_null(const void* p) { return p == NULL || is_in_heap(p); })305306// Reserve Java heap and determine CompressedOops mode307static ReservedHeapSpace reserve_heap(size_t heap_size, size_t alignment);308309// Global OopStorages310static OopStorage* vm_weak();311static OopStorage* vm_global();312static void oopstorage_init();313314// Testers315static bool is_bootstrapping() { return _bootstrapping; }316static bool is_module_initialized() { return _module_initialized; }317static bool is_fully_initialized() { return _fully_initialized; }318319static bool on_page_boundary(void* addr);320static bool should_fill_in_stack_trace(Handle throwable);321static void check_alignment(uintx size, uintx alignment, const char* name);322323// CDS support324static void serialize(SerializeClosure* f);325326// Apply "f" to all klasses for basic types (classes not present in327// SystemDictionary).328static void basic_type_classes_do(void f(Klass*));329static void basic_type_classes_do(KlassClosure* closure);330static void metaspace_pointers_do(MetaspaceClosure* it);331332// Debugging333enum VERIFY_FLAGS {334Verify_Threads = 1,335Verify_Heap = 2,336Verify_SymbolTable = 4,337Verify_StringTable = 8,338Verify_CodeCache = 16,339Verify_SystemDictionary = 32,340Verify_ClassLoaderDataGraph = 64,341Verify_MetaspaceUtils = 128,342Verify_JNIHandles = 256,343Verify_CodeCacheOops = 512,344Verify_ResolvedMethodTable = 1024,345Verify_StringDedup = 2048,346Verify_All = -1347};348static void initialize_verify_flags();349static bool should_verify_subset(uint subset);350static bool verify_in_progress() { return _verify_in_progress; }351static void verify(VerifyOption option, const char* prefix);352static void verify(const char* prefix) {353verify(VerifyOption_Default, prefix);354}355static void verify() {356verify("");357}358359static int verify_count() { return _verify_count; }360static void print_on(outputStream* st);361static void print_heap_at_SIGBREAK();362363// Change the number of dummy objects kept reachable by the full gc dummy364// array; this should trigger relocation in a sliding compaction collector.365debug_only(static bool release_fullgc_alot_dummy();)366// The non-oop pattern (see compiledIC.hpp, etc)367static void* non_oop_word();368static bool contains_non_oop_word(void* p);369370// Oop verification (see MacroAssembler::verify_oop)371static uintptr_t verify_oop_mask() PRODUCT_RETURN0;372static uintptr_t verify_oop_bits() PRODUCT_RETURN0;373static uintptr_t verify_mark_bits() PRODUCT_RETURN0;374static uintptr_t verify_mark_mask() PRODUCT_RETURN0;375376// Compiler support377static int base_vtable_size() { return _base_vtable_size; }378};379380#endif // SHARE_MEMORY_UNIVERSE_HPP381382383