Path: blob/master/src/hotspot/share/runtime/handles.inline.hpp
40951 views
/*1* Copyright (c) 1998, 2020, 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_RUNTIME_HANDLES_INLINE_HPP25#define SHARE_RUNTIME_HANDLES_INLINE_HPP2627#include "runtime/handles.hpp"2829#include "runtime/thread.hpp"30#include "oops/metadata.hpp"31#include "oops/oop.hpp"3233// these inline functions are in a separate file to break an include cycle34// between Thread and Handle3536inline Handle::Handle(Thread* thread, oop obj) {37assert(thread == Thread::current(), "sanity check");38if (obj == NULL) {39_handle = NULL;40} else {41_handle = thread->handle_area()->allocate_handle(obj);42}43}4445// Inline constructors for Specific Handles for different oop types46#define DEF_HANDLE_CONSTR(type, is_a) \47inline type##Handle::type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \48assert(is_null() || ((oop)obj)->is_a(), "illegal type"); \49}5051DEF_HANDLE_CONSTR(instance , is_instance_noinline )52DEF_HANDLE_CONSTR(array , is_array_noinline )53DEF_HANDLE_CONSTR(objArray , is_objArray_noinline )54DEF_HANDLE_CONSTR(typeArray, is_typeArray_noinline)5556// Constructor for metadata handles57#define DEF_METADATA_HANDLE_FN(name, type) \58inline name##Handle::name##Handle(Thread* thread, type* obj) : _value(obj), _thread(thread) { \59if (obj != NULL) { \60assert(((Metadata*)obj)->is_valid(), "obj is valid"); \61assert(_thread == Thread::current(), "thread must be current"); \62assert(_thread->is_in_live_stack((address)this), "not on stack?"); \63_thread->metadata_handles()->push((Metadata*)obj); \64} \65} \6667DEF_METADATA_HANDLE_FN(method, Method)68DEF_METADATA_HANDLE_FN(constantPool, ConstantPool)6970inline void HandleMark::push() {71// This is intentionally a NOP. pop_and_restore will reset72// values to the HandleMark further down the stack, typically73// in JavaCalls::call_helper.74debug_only(_area->_handle_mark_nesting++);75}7677inline void HandleMark::pop_and_restore() {78// Delete later chunks79if(_chunk->next() != NULL) {80assert(_area->size_in_bytes() > size_in_bytes(), "Sanity check");81chop_later_chunks();82} else {83assert(_area->size_in_bytes() == size_in_bytes(), "Sanity check");84}85// Roll back arena to saved top markers86_area->_chunk = _chunk;87_area->_hwm = _hwm;88_area->_max = _max;89debug_only(_area->_handle_mark_nesting--);90}9192inline HandleMarkCleaner::HandleMarkCleaner(Thread* thread) {93_thread = thread;94_thread->last_handle_mark()->push();95}9697inline HandleMarkCleaner::~HandleMarkCleaner() {98_thread->last_handle_mark()->pop_and_restore();99}100101#endif // SHARE_RUNTIME_HANDLES_INLINE_HPP102103104