OpenJDK / jdk / jdk
changeset 53682:e30211561a17
8218565: HandleMark cleanup
Reviewed-by: coleenp, kbarrett, rehn
author | redestad |
---|---|
date | Thu, 07 Feb 2019 10:26:32 +0100 |
parents | fa0d9fc371bb |
children | 48ff68e2fe5c |
files | src/hotspot/share/runtime/handles.cpp src/hotspot/share/runtime/handles.hpp src/hotspot/share/runtime/handles.inline.hpp |
diffstat | 3 files changed, 21 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/hotspot/share/runtime/handles.cpp Thu Feb 07 12:11:41 2019 +0530 +++ b/src/hotspot/share/runtime/handles.cpp Thu Feb 07 10:26:32 2019 +0100 @@ -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 @@ 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 @@ _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); }
--- a/src/hotspot/share/runtime/handles.hpp Thu Feb 07 12:11:41 2019 +0530 +++ b/src/hotspot/share/runtime/handles.hpp Thu Feb 07 10:26:32 2019 +0100 @@ -253,6 +253,8 @@ 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); }
--- a/src/hotspot/share/runtime/handles.inline.hpp Thu Feb 07 12:11:41 2019 +0530 +++ b/src/hotspot/share/runtime/handles.inline.hpp Thu Feb 07 10:26:32 2019 +0100 @@ -79,7 +79,6 @@ 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::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) {