Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/handles.inline.hpp
32285 views
/*1* Copyright (c) 1998, 2013, 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_VM_RUNTIME_HANDLES_INLINE_HPP25#define SHARE_VM_RUNTIME_HANDLES_INLINE_HPP2627#include "runtime/handles.hpp"28#include "runtime/thread.inline.hpp"2930// these inline functions are in a separate file to break an include cycle31// between Thread and Handle3233inline Handle::Handle(oop obj) {34if (obj == NULL) {35_handle = NULL;36} else {37_handle = Thread::current()->handle_area()->allocate_handle(obj);38}39}404142#ifndef ASSERT43inline Handle::Handle(Thread* thread, oop obj) {44assert(thread == Thread::current(), "sanity check");45if (obj == NULL) {46_handle = NULL;47} else {48_handle = thread->handle_area()->allocate_handle(obj);49}50}51#endif // ASSERT5253// Constructors for metadata handles54#define DEF_METADATA_HANDLE_FN(name, type) \55inline name##Handle::name##Handle(type* obj) : _value(obj), _thread(NULL) { \56if (obj != NULL) { \57assert(((Metadata*)obj)->is_valid(), "obj is valid"); \58_thread = Thread::current(); \59assert (_thread->is_in_stack((address)this), "not on stack?"); \60_thread->metadata_handles()->push((Metadata*)obj); \61} \62} \63inline name##Handle::name##Handle(Thread* thread, type* obj) : _value(obj), _thread(thread) { \64if (obj != NULL) { \65assert(((Metadata*)obj)->is_valid(), "obj is valid"); \66assert(_thread == Thread::current(), "thread must be current"); \67assert (_thread->is_in_stack((address)this), "not on stack?"); \68_thread->metadata_handles()->push((Metadata*)obj); \69} \70} \71inline name##Handle::name##Handle(const name##Handle &h) { \72_value = h._value; \73if (_value != NULL) { \74assert(_value->is_valid(), "obj is valid"); \75if (h._thread != NULL) { \76assert(h._thread == Thread::current(), "thread must be current");\77_thread = h._thread; \78} else { \79_thread = Thread::current(); \80} \81assert (_thread->is_in_stack((address)this), "not on stack?"); \82_thread->metadata_handles()->push((Metadata*)_value); \83} else { \84_thread = NULL; \85} \86} \87inline name##Handle& name##Handle::operator=(const name##Handle &s) { \88remove(); \89_value = s._value; \90if (_value != NULL) { \91assert(_value->is_valid(), "obj is valid"); \92if (s._thread != NULL) { \93assert(s._thread == Thread::current(), "thread must be current");\94_thread = s._thread; \95} else { \96_thread = Thread::current(); \97} \98assert (_thread->is_in_stack((address)this), "not on stack?"); \99_thread->metadata_handles()->push((Metadata*)_value); \100} else { \101_thread = NULL; \102} \103return *this; \104} \105inline void name##Handle::remove() { \106if (_value != NULL) { \107int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \108assert(i!=-1, "not in metadata_handles list"); \109_thread->metadata_handles()->remove_at(i); \110} \111} \112inline name##Handle::~name##Handle () { remove(); } \113114DEF_METADATA_HANDLE_FN(method, Method)115DEF_METADATA_HANDLE_FN(constantPool, ConstantPool)116117inline HandleMark::HandleMark() {118initialize(Thread::current());119}120121122inline void HandleMark::push() {123// This is intentionally a NOP. pop_and_restore will reset124// values to the HandleMark further down the stack, typically125// in JavaCalls::call_helper.126debug_only(_area->_handle_mark_nesting++);127}128129inline void HandleMark::pop_and_restore() {130HandleArea* area = _area; // help compilers with poor alias analysis131// Delete later chunks132if( _chunk->next() ) {133// reset arena size before delete chunks. Otherwise, the total134// arena size could exceed total chunk size135assert(area->size_in_bytes() > size_in_bytes(), "Sanity check");136area->set_size_in_bytes(size_in_bytes());137_chunk->next_chop();138} else {139assert(area->size_in_bytes() == size_in_bytes(), "Sanity check");140}141// Roll back arena to saved top markers142area->_chunk = _chunk;143area->_hwm = _hwm;144area->_max = _max;145debug_only(area->_handle_mark_nesting--);146}147148#endif // SHARE_VM_RUNTIME_HANDLES_INLINE_HPP149150151