aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_RUNTIME_HANDLES_INLINE_HPP aoqi@0: #define SHARE_VM_RUNTIME_HANDLES_INLINE_HPP aoqi@0: aoqi@0: #include "runtime/handles.hpp" aoqi@0: #include "runtime/thread.inline.hpp" aoqi@0: aoqi@0: // these inline functions are in a separate file to break an include cycle aoqi@0: // between Thread and Handle aoqi@0: aoqi@0: inline Handle::Handle(oop obj) { aoqi@0: if (obj == NULL) { aoqi@0: _handle = NULL; aoqi@0: } else { aoqi@0: _handle = Thread::current()->handle_area()->allocate_handle(obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: #ifndef ASSERT aoqi@0: inline Handle::Handle(Thread* thread, oop obj) { aoqi@0: assert(thread == Thread::current(), "sanity check"); aoqi@0: if (obj == NULL) { aoqi@0: _handle = NULL; aoqi@0: } else { aoqi@0: _handle = thread->handle_area()->allocate_handle(obj); aoqi@0: } aoqi@0: } aoqi@0: #endif // ASSERT aoqi@0: aoqi@0: // Constructors for metadata handles aoqi@0: #define DEF_METADATA_HANDLE_FN(name, type) \ aoqi@0: inline name##Handle::name##Handle(type* obj) : _value(obj), _thread(NULL) { \ aoqi@0: if (obj != NULL) { \ aoqi@0: assert(((Metadata*)obj)->is_valid(), "obj is valid"); \ aoqi@0: _thread = Thread::current(); \ aoqi@0: assert (_thread->is_in_stack((address)this), "not on stack?"); \ aoqi@0: _thread->metadata_handles()->push((Metadata*)obj); \ aoqi@0: } \ aoqi@0: } \ aoqi@0: inline name##Handle::name##Handle(Thread* thread, type* obj) : _value(obj), _thread(thread) { \ aoqi@0: if (obj != NULL) { \ aoqi@0: assert(((Metadata*)obj)->is_valid(), "obj is valid"); \ aoqi@0: assert(_thread == Thread::current(), "thread must be current"); \ aoqi@0: assert (_thread->is_in_stack((address)this), "not on stack?"); \ aoqi@0: _thread->metadata_handles()->push((Metadata*)obj); \ aoqi@0: } \ aoqi@0: } \ aoqi@0: inline name##Handle::name##Handle(const name##Handle &h) { \ aoqi@0: _value = h._value; \ aoqi@0: if (_value != NULL) { \ aoqi@0: assert(_value->is_valid(), "obj is valid"); \ aoqi@0: if (h._thread != NULL) { \ aoqi@0: assert(h._thread == Thread::current(), "thread must be current");\ aoqi@0: _thread = h._thread; \ aoqi@0: } else { \ aoqi@0: _thread = Thread::current(); \ aoqi@0: } \ aoqi@0: assert (_thread->is_in_stack((address)this), "not on stack?"); \ aoqi@0: _thread->metadata_handles()->push((Metadata*)_value); \ aoqi@0: } else { \ aoqi@0: _thread = NULL; \ aoqi@0: } \ aoqi@0: } \ aoqi@0: inline name##Handle& name##Handle::operator=(const name##Handle &s) { \ aoqi@0: remove(); \ aoqi@0: _value = s._value; \ aoqi@0: if (_value != NULL) { \ aoqi@0: assert(_value->is_valid(), "obj is valid"); \ aoqi@0: if (s._thread != NULL) { \ aoqi@0: assert(s._thread == Thread::current(), "thread must be current");\ aoqi@0: _thread = s._thread; \ aoqi@0: } else { \ aoqi@0: _thread = Thread::current(); \ aoqi@0: } \ aoqi@0: assert (_thread->is_in_stack((address)this), "not on stack?"); \ aoqi@0: _thread->metadata_handles()->push((Metadata*)_value); \ aoqi@0: } else { \ aoqi@0: _thread = NULL; \ aoqi@0: } \ aoqi@0: return *this; \ aoqi@0: } \ aoqi@0: inline void name##Handle::remove() { \ aoqi@0: if (_value != NULL) { \ aoqi@0: int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \ aoqi@0: assert(i!=-1, "not in metadata_handles list"); \ aoqi@0: _thread->metadata_handles()->remove_at(i); \ aoqi@0: } \ aoqi@0: } \ aoqi@0: inline name##Handle::~name##Handle () { remove(); } \ aoqi@0: aoqi@0: DEF_METADATA_HANDLE_FN(method, Method) aoqi@0: DEF_METADATA_HANDLE_FN(constantPool, ConstantPool) aoqi@0: aoqi@0: inline HandleMark::HandleMark() { aoqi@0: initialize(Thread::current()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: inline void HandleMark::push() { aoqi@0: // This is intentionally a NOP. pop_and_restore will reset aoqi@0: // values to the HandleMark further down the stack, typically aoqi@0: // in JavaCalls::call_helper. aoqi@0: debug_only(_area->_handle_mark_nesting++); aoqi@0: } aoqi@0: aoqi@0: inline void HandleMark::pop_and_restore() { aoqi@0: HandleArea* area = _area; // help compilers with poor alias analysis aoqi@0: // Delete later chunks aoqi@0: if( _chunk->next() ) { aoqi@0: // reset arena size before delete chunks. Otherwise, the total aoqi@0: // arena size could exceed total chunk size aoqi@0: assert(area->size_in_bytes() > size_in_bytes(), "Sanity check"); aoqi@0: area->set_size_in_bytes(size_in_bytes()); aoqi@0: _chunk->next_chop(); aoqi@0: } else { aoqi@0: assert(area->size_in_bytes() == size_in_bytes(), "Sanity check"); aoqi@0: } aoqi@0: // Roll back arena to saved top markers aoqi@0: area->_chunk = _chunk; aoqi@0: area->_hwm = _hwm; aoqi@0: area->_max = _max; aoqi@0: debug_only(area->_handle_mark_nesting--); aoqi@0: } aoqi@0: aoqi@0: #endif // SHARE_VM_RUNTIME_HANDLES_INLINE_HPP