mirror of
https://github.com/darlinghq/darling-openjdk.git
synced 2024-11-23 12:29:56 +00:00
8218565: HandleMark cleanup
Reviewed-by: coleenp, kbarrett, rehn
This commit is contained in:
parent
31e3c0800c
commit
551a272ced
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2019, 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
|
||||
@ -26,7 +26,6 @@
|
||||
#include "memory/allocation.inline.hpp"
|
||||
#include "oops/constantPool.hpp"
|
||||
#include "oops/oop.inline.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/thread.inline.hpp"
|
||||
|
||||
@ -102,9 +101,6 @@ static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
|
||||
return handles_visited;
|
||||
}
|
||||
|
||||
// Used for debugging handle allocation.
|
||||
NOT_PRODUCT(jint _nof_handlemarks = 0;)
|
||||
|
||||
void HandleArea::oops_do(OopClosure* f) {
|
||||
uintx handles_visited = 0;
|
||||
// First handle the current chunk. It is filled to the high water mark.
|
||||
@ -130,46 +126,35 @@ void HandleMark::initialize(Thread* thread) {
|
||||
_size_in_bytes = _area->_size_in_bytes;
|
||||
debug_only(_area->_handle_mark_nesting++);
|
||||
assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks");
|
||||
debug_only(Atomic::inc(&_nof_handlemarks);)
|
||||
|
||||
// Link this in the thread
|
||||
set_previous_handle_mark(thread->last_handle_mark());
|
||||
thread->set_last_handle_mark(this);
|
||||
}
|
||||
|
||||
|
||||
HandleMark::~HandleMark() {
|
||||
HandleArea* area = _area; // help compilers with poor alias analysis
|
||||
assert(area == _thread->handle_area(), "sanity check");
|
||||
assert(area->_handle_mark_nesting > 0, "must stack allocate HandleMarks" );
|
||||
debug_only(area->_handle_mark_nesting--);
|
||||
assert(_area == _thread->handle_area(), "sanity check");
|
||||
assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks" );
|
||||
|
||||
// Delete later chunks
|
||||
if( _chunk->next() ) {
|
||||
// reset arena size before delete chunks. Otherwise, the total
|
||||
// arena size could exceed total chunk size
|
||||
assert(area->size_in_bytes() > size_in_bytes(), "Sanity check");
|
||||
area->set_size_in_bytes(size_in_bytes());
|
||||
_chunk->next_chop();
|
||||
} else {
|
||||
assert(area->size_in_bytes() == size_in_bytes(), "Sanity check");
|
||||
}
|
||||
// Roll back arena to saved top markers
|
||||
area->_chunk = _chunk;
|
||||
area->_hwm = _hwm;
|
||||
area->_max = _max;
|
||||
pop_and_restore();
|
||||
#ifdef ASSERT
|
||||
// clear out first chunk (to detect allocation bugs)
|
||||
if (ZapVMHandleArea) {
|
||||
memset(_hwm, badHandleValue, _max - _hwm);
|
||||
}
|
||||
Atomic::dec(&_nof_handlemarks);
|
||||
#endif
|
||||
|
||||
// Unlink this from the thread
|
||||
_thread->set_last_handle_mark(previous_handle_mark());
|
||||
}
|
||||
|
||||
void HandleMark::chop_later_chunks() {
|
||||
// reset arena size before delete chunks. Otherwise, the total
|
||||
// arena size could exceed total chunk size
|
||||
_area->set_size_in_bytes(size_in_bytes());
|
||||
_chunk->next_chop();
|
||||
}
|
||||
|
||||
void* HandleMark::operator new(size_t size) throw() {
|
||||
return AllocateHeap(size, mtThread);
|
||||
}
|
||||
|
@ -253,6 +253,8 @@ class HandleMark {
|
||||
HandleMark* previous_handle_mark() const { return _previous_handle_mark; }
|
||||
|
||||
size_t size_in_bytes() const { return _size_in_bytes; }
|
||||
// remove all chunks beginning with the next
|
||||
void chop_later_chunks();
|
||||
public:
|
||||
HandleMark(); // see handles_inline.hpp
|
||||
HandleMark(Thread* thread) { initialize(thread); }
|
||||
|
@ -79,7 +79,6 @@ inline HandleMark::HandleMark() {
|
||||
initialize(Thread::current());
|
||||
}
|
||||
|
||||
|
||||
inline void HandleMark::push() {
|
||||
// This is intentionally a NOP. pop_and_restore will reset
|
||||
// values to the HandleMark further down the stack, typically
|
||||
@ -88,22 +87,18 @@ inline void HandleMark::push() {
|
||||
}
|
||||
|
||||
inline void HandleMark::pop_and_restore() {
|
||||
HandleArea* area = _area; // help compilers with poor alias analysis
|
||||
// Delete later chunks
|
||||
if( _chunk->next() ) {
|
||||
// reset arena size before delete chunks. Otherwise, the total
|
||||
// arena size could exceed total chunk size
|
||||
assert(area->size_in_bytes() > size_in_bytes(), "Sanity check");
|
||||
area->set_size_in_bytes(size_in_bytes());
|
||||
_chunk->next_chop();
|
||||
if(_chunk->next() != NULL) {
|
||||
assert(_area->size_in_bytes() > size_in_bytes(), "Sanity check");
|
||||
chop_later_chunks();
|
||||
} else {
|
||||
assert(area->size_in_bytes() == size_in_bytes(), "Sanity check");
|
||||
assert(_area->size_in_bytes() == size_in_bytes(), "Sanity check");
|
||||
}
|
||||
// Roll back arena to saved top markers
|
||||
area->_chunk = _chunk;
|
||||
area->_hwm = _hwm;
|
||||
area->_max = _max;
|
||||
debug_only(area->_handle_mark_nesting--);
|
||||
_area->_chunk = _chunk;
|
||||
_area->_hwm = _hwm;
|
||||
_area->_max = _max;
|
||||
debug_only(_area->_handle_mark_nesting--);
|
||||
}
|
||||
|
||||
inline HandleMarkCleaner::HandleMarkCleaner(Thread* thread) {
|
||||
|
Loading…
Reference in New Issue
Block a user