8334223: Make Arena MEMFLAGs immutable
Reviewed-by: jsjolen, azafari, gziemski
This commit is contained in:
parent
e527e1c32f
commit
974dca80df
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,7 +32,7 @@
|
||||
// Create a CompilerThread
|
||||
CompilerThread::CompilerThread(CompileQueue* queue,
|
||||
CompilerCounters* counters)
|
||||
: JavaThread(&CompilerThread::thread_entry) {
|
||||
: JavaThread(&CompilerThread::thread_entry, 0, mtCompiler) {
|
||||
_env = nullptr;
|
||||
_log = nullptr;
|
||||
_task = nullptr;
|
||||
@ -43,9 +43,6 @@ CompilerThread::CompilerThread(CompileQueue* queue,
|
||||
_compiler = nullptr;
|
||||
_arena_stat = CompilationMemoryStatistic::enabled() ? new ArenaStatCounter : nullptr;
|
||||
|
||||
// Compiler uses resource area for compilation, let's bias it to mtCompiler
|
||||
resource_area()->bias_to(mtCompiler);
|
||||
|
||||
#ifndef PRODUCT
|
||||
_ideal_graph_printer = nullptr;
|
||||
#endif
|
||||
|
@ -209,7 +209,12 @@ void Chunk::next_chop(Chunk* k) {
|
||||
k->_next = nullptr;
|
||||
}
|
||||
|
||||
Arena::Arena(MEMFLAGS flag, Tag tag, size_t init_size) : _flags(flag), _tag(tag), _size_in_bytes(0) {
|
||||
Arena::Arena(MEMFLAGS flag, Tag tag, size_t init_size) :
|
||||
_flags(flag), _tag(tag),
|
||||
_size_in_bytes(0),
|
||||
_first(nullptr), _chunk(nullptr),
|
||||
_hwm(nullptr), _max(nullptr)
|
||||
{
|
||||
init_size = ARENA_ALIGN(init_size);
|
||||
_chunk = ChunkPool::allocate_chunk(init_size, AllocFailStrategy::EXIT_OOM);
|
||||
_first = _chunk;
|
||||
@ -219,15 +224,6 @@ Arena::Arena(MEMFLAGS flag, Tag tag, size_t init_size) : _flags(flag), _tag(tag)
|
||||
set_size_in_bytes(init_size);
|
||||
}
|
||||
|
||||
Arena::Arena(MEMFLAGS flag, Tag tag) : _flags(flag), _tag(tag), _size_in_bytes(0) {
|
||||
_chunk = ChunkPool::allocate_chunk(Chunk::init_size, AllocFailStrategy::EXIT_OOM);
|
||||
_first = _chunk;
|
||||
_hwm = _chunk->bottom(); // Save the cached hwm, max
|
||||
_max = _chunk->top();
|
||||
MemTracker::record_new_arena(flag);
|
||||
set_size_in_bytes(Chunk::init_size);
|
||||
}
|
||||
|
||||
Arena::~Arena() {
|
||||
destruct_contents();
|
||||
MemTracker::record_arena_free(_flags);
|
||||
|
@ -94,21 +94,23 @@ public:
|
||||
tag_node // C2 Node arena
|
||||
};
|
||||
|
||||
private:
|
||||
const MEMFLAGS _flags; // Memory tracking flags
|
||||
const Tag _tag;
|
||||
size_t _size_in_bytes; // Size of arena (used for native memory tracking)
|
||||
|
||||
protected:
|
||||
friend class HandleMark;
|
||||
friend class NoHandleMark;
|
||||
friend class VMStructs;
|
||||
|
||||
MEMFLAGS _flags; // Memory tracking flags
|
||||
const Tag _tag;
|
||||
uint32_t _init_size;
|
||||
Chunk* _first; // First chunk
|
||||
Chunk* _chunk; // current chunk
|
||||
char* _hwm; // High water mark
|
||||
char* _max; // and max in current chunk
|
||||
|
||||
// Get a new Chunk of at least size x
|
||||
void* grow(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
|
||||
size_t _size_in_bytes; // Size of arena (used for native memory tracking)
|
||||
|
||||
void* internal_amalloc(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
|
||||
assert(is_aligned(x, BytesPerWord), "misaligned size");
|
||||
@ -124,8 +126,7 @@ protected:
|
||||
public:
|
||||
// Start the chunk_pool cleaner task
|
||||
static void start_chunk_pool_cleaner_task();
|
||||
Arena(MEMFLAGS memflag, Tag tag = Tag::tag_other);
|
||||
Arena(MEMFLAGS memflag, Tag tag, size_t init_size);
|
||||
Arena(MEMFLAGS memflag, Tag tag = Tag::tag_other, size_t init_size = Chunk::init_size);
|
||||
~Arena();
|
||||
void destruct_contents();
|
||||
char* hwm() const { return _hwm; }
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,17 +30,6 @@
|
||||
#include "runtime/javaThread.hpp"
|
||||
#include "utilities/vmError.hpp"
|
||||
|
||||
void ResourceArea::bias_to(MEMFLAGS new_flags) {
|
||||
if (new_flags != _flags) {
|
||||
size_t size = size_in_bytes();
|
||||
MemTracker::record_arena_size_change(-ssize_t(size), _flags);
|
||||
MemTracker::record_arena_free(_flags);
|
||||
MemTracker::record_new_arena(new_flags);
|
||||
MemTracker::record_arena_size_change(ssize_t(size), new_flags);
|
||||
_flags = new_flags;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ASSERT
|
||||
|
||||
ResourceMark::ResourceMark(ResourceArea* area, Thread* thread) :
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -60,10 +60,6 @@ public:
|
||||
|
||||
char* allocate_bytes(size_t size, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
|
||||
|
||||
// Bias this resource area to specific memory type
|
||||
// (by default, ResourceArea is tagged as mtThread, per-thread general purpose storage)
|
||||
void bias_to(MEMFLAGS flags);
|
||||
|
||||
DEBUG_ONLY(int nesting() const { return _nesting; })
|
||||
|
||||
// Capture the state of a ResourceArea needed by a ResourceMark for
|
||||
@ -81,7 +77,7 @@ public:
|
||||
_chunk(area->_chunk),
|
||||
_hwm(area->_hwm),
|
||||
_max(area->_max),
|
||||
_size_in_bytes(area->_size_in_bytes)
|
||||
_size_in_bytes(area->size_in_bytes())
|
||||
DEBUG_ONLY(COMMA _nesting(area->_nesting))
|
||||
{}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012 Red Hat, Inc.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2024 Red Hat, Inc.
|
||||
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -3775,7 +3775,7 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
|
||||
|
||||
// Create a thread and mark it as attaching so it will be skipped by the
|
||||
// ThreadsListEnumerator - see CR 6404306
|
||||
JavaThread* thread = new JavaThread(true);
|
||||
JavaThread* thread = JavaThread::create_attaching_thread();
|
||||
|
||||
// Set correct safepoint info. The thread is going to call into Java when
|
||||
// initializing the Java level thread object. Hence, the correct state must
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -187,7 +187,7 @@ class HandleArea: public Arena {
|
||||
HandleArea* _prev; // link to outer (older) area
|
||||
public:
|
||||
// Constructor
|
||||
HandleArea(HandleArea* prev) : Arena(mtThread, Tag::tag_ha, Chunk::tiny_size) {
|
||||
HandleArea(MEMFLAGS flags, HandleArea* prev) : Arena(flags, Tag::tag_ha, Chunk::tiny_size) {
|
||||
debug_only(_handle_mark_nesting = 0);
|
||||
debug_only(_no_handle_mark_nesting = 0);
|
||||
_prev = prev;
|
||||
|
@ -409,9 +409,9 @@ void JavaThread::check_for_valid_safepoint_state() {
|
||||
|
||||
// A JavaThread is a normal Java thread
|
||||
|
||||
JavaThread::JavaThread() :
|
||||
JavaThread::JavaThread(MEMFLAGS flags) :
|
||||
Thread(flags),
|
||||
// Initialize fields
|
||||
|
||||
_on_thread_list(false),
|
||||
DEBUG_ONLY(_java_call_counter(0) COMMA)
|
||||
_entry_point(nullptr),
|
||||
@ -525,13 +525,12 @@ JavaThread::JavaThread() :
|
||||
assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
|
||||
}
|
||||
|
||||
JavaThread::JavaThread(bool is_attaching_via_jni) : JavaThread() {
|
||||
if (is_attaching_via_jni) {
|
||||
_jni_attach_state = _attaching_via_jni;
|
||||
}
|
||||
JavaThread* JavaThread::create_attaching_thread() {
|
||||
JavaThread* jt = new JavaThread();
|
||||
jt->_jni_attach_state = _attaching_via_jni;
|
||||
return jt;
|
||||
}
|
||||
|
||||
|
||||
// interrupt support
|
||||
|
||||
void JavaThread::interrupt() {
|
||||
@ -634,8 +633,7 @@ void JavaThread::block_if_vm_exited() {
|
||||
}
|
||||
}
|
||||
|
||||
JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : JavaThread() {
|
||||
_jni_attach_state = _not_attaching_via_jni;
|
||||
JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz, MEMFLAGS flags) : JavaThread(flags) {
|
||||
set_entry_point(entry_point);
|
||||
// Create the native thread itself.
|
||||
// %note runtime_23
|
||||
|
@ -478,11 +478,13 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
JavaThread(); // delegating constructor
|
||||
JavaThread(bool is_attaching_via_jni); // for main thread and JNI attached threads
|
||||
JavaThread(ThreadFunction entry_point, size_t stack_size = 0);
|
||||
JavaThread(MEMFLAGS flags = mtThread); // delegating constructor
|
||||
JavaThread(ThreadFunction entry_point, size_t stack_size = 0, MEMFLAGS flags = mtThread);
|
||||
~JavaThread();
|
||||
|
||||
// Factory method to create a new JavaThread whose attach state is "is attaching"
|
||||
static JavaThread* create_attaching_thread();
|
||||
|
||||
#ifdef ASSERT
|
||||
// verify this JavaThread hasn't be published in the Threads::list yet
|
||||
void verify_not_published();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
|
@ -64,7 +64,7 @@ THREAD_LOCAL Thread* Thread::_thr_current = nullptr;
|
||||
|
||||
DEBUG_ONLY(Thread* Thread::_starting_thread = nullptr;)
|
||||
|
||||
Thread::Thread() {
|
||||
Thread::Thread(MEMFLAGS flags) {
|
||||
|
||||
DEBUG_ONLY(_run_state = PRE_CALL_RUN;)
|
||||
|
||||
@ -78,9 +78,9 @@ Thread::Thread() {
|
||||
|
||||
// allocated data structures
|
||||
set_osthread(nullptr);
|
||||
set_resource_area(new (mtThread)ResourceArea());
|
||||
set_resource_area(new (flags) ResourceArea(flags));
|
||||
DEBUG_ONLY(_current_resource_mark = nullptr;)
|
||||
set_handle_area(new (mtThread) HandleArea(nullptr));
|
||||
set_handle_area(new (flags) HandleArea(flags, nullptr));
|
||||
set_metadata_handles(new (mtClass) GrowableArray<Metadata*>(30, mtClass));
|
||||
set_last_handle_mark(nullptr);
|
||||
DEBUG_ONLY(_missed_ic_stub_refill_verifier = nullptr);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -277,7 +277,7 @@ class Thread: public ThreadShadow {
|
||||
// is waiting to lock
|
||||
public:
|
||||
// Constructor
|
||||
Thread();
|
||||
Thread(MEMFLAGS flag = mtThread);
|
||||
virtual ~Thread() = 0; // Thread is abstract.
|
||||
|
||||
// Manage Thread::current()
|
||||
|
Loading…
Reference in New Issue
Block a user