src/share/vm/runtime/handles.inline.hpp

Thu, 24 May 2018 19:24:53 +0800

author
aoqi
date
Thu, 24 May 2018 19:24:53 +0800
changeset 8861
2a33b32dd03c
parent 6876
710a3c8b516e
permissions
-rw-r--r--

#7046 Disable the compilation when branch offset is beyond short branch
Contributed-by: fujie, aoqi

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_RUNTIME_HANDLES_INLINE_HPP
aoqi@0 26 #define SHARE_VM_RUNTIME_HANDLES_INLINE_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/handles.hpp"
aoqi@0 29 #include "runtime/thread.inline.hpp"
aoqi@0 30
aoqi@0 31 // these inline functions are in a separate file to break an include cycle
aoqi@0 32 // between Thread and Handle
aoqi@0 33
aoqi@0 34 inline Handle::Handle(oop obj) {
aoqi@0 35 if (obj == NULL) {
aoqi@0 36 _handle = NULL;
aoqi@0 37 } else {
aoqi@0 38 _handle = Thread::current()->handle_area()->allocate_handle(obj);
aoqi@0 39 }
aoqi@0 40 }
aoqi@0 41
aoqi@0 42
aoqi@0 43 #ifndef ASSERT
aoqi@0 44 inline Handle::Handle(Thread* thread, oop obj) {
aoqi@0 45 assert(thread == Thread::current(), "sanity check");
aoqi@0 46 if (obj == NULL) {
aoqi@0 47 _handle = NULL;
aoqi@0 48 } else {
aoqi@0 49 _handle = thread->handle_area()->allocate_handle(obj);
aoqi@0 50 }
aoqi@0 51 }
aoqi@0 52 #endif // ASSERT
aoqi@0 53
aoqi@0 54 // Constructors for metadata handles
aoqi@0 55 #define DEF_METADATA_HANDLE_FN(name, type) \
aoqi@0 56 inline name##Handle::name##Handle(type* obj) : _value(obj), _thread(NULL) { \
aoqi@0 57 if (obj != NULL) { \
aoqi@0 58 assert(((Metadata*)obj)->is_valid(), "obj is valid"); \
aoqi@0 59 _thread = Thread::current(); \
aoqi@0 60 assert (_thread->is_in_stack((address)this), "not on stack?"); \
aoqi@0 61 _thread->metadata_handles()->push((Metadata*)obj); \
aoqi@0 62 } \
aoqi@0 63 } \
aoqi@0 64 inline name##Handle::name##Handle(Thread* thread, type* obj) : _value(obj), _thread(thread) { \
aoqi@0 65 if (obj != NULL) { \
aoqi@0 66 assert(((Metadata*)obj)->is_valid(), "obj is valid"); \
aoqi@0 67 assert(_thread == Thread::current(), "thread must be current"); \
aoqi@0 68 assert (_thread->is_in_stack((address)this), "not on stack?"); \
aoqi@0 69 _thread->metadata_handles()->push((Metadata*)obj); \
aoqi@0 70 } \
aoqi@0 71 } \
aoqi@0 72 inline name##Handle::name##Handle(const name##Handle &h) { \
aoqi@0 73 _value = h._value; \
aoqi@0 74 if (_value != NULL) { \
aoqi@0 75 assert(_value->is_valid(), "obj is valid"); \
aoqi@0 76 if (h._thread != NULL) { \
aoqi@0 77 assert(h._thread == Thread::current(), "thread must be current");\
aoqi@0 78 _thread = h._thread; \
aoqi@0 79 } else { \
aoqi@0 80 _thread = Thread::current(); \
aoqi@0 81 } \
aoqi@0 82 assert (_thread->is_in_stack((address)this), "not on stack?"); \
aoqi@0 83 _thread->metadata_handles()->push((Metadata*)_value); \
aoqi@0 84 } else { \
aoqi@0 85 _thread = NULL; \
aoqi@0 86 } \
aoqi@0 87 } \
aoqi@0 88 inline name##Handle& name##Handle::operator=(const name##Handle &s) { \
aoqi@0 89 remove(); \
aoqi@0 90 _value = s._value; \
aoqi@0 91 if (_value != NULL) { \
aoqi@0 92 assert(_value->is_valid(), "obj is valid"); \
aoqi@0 93 if (s._thread != NULL) { \
aoqi@0 94 assert(s._thread == Thread::current(), "thread must be current");\
aoqi@0 95 _thread = s._thread; \
aoqi@0 96 } else { \
aoqi@0 97 _thread = Thread::current(); \
aoqi@0 98 } \
aoqi@0 99 assert (_thread->is_in_stack((address)this), "not on stack?"); \
aoqi@0 100 _thread->metadata_handles()->push((Metadata*)_value); \
aoqi@0 101 } else { \
aoqi@0 102 _thread = NULL; \
aoqi@0 103 } \
aoqi@0 104 return *this; \
aoqi@0 105 } \
aoqi@0 106 inline void name##Handle::remove() { \
aoqi@0 107 if (_value != NULL) { \
aoqi@0 108 int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \
aoqi@0 109 assert(i!=-1, "not in metadata_handles list"); \
aoqi@0 110 _thread->metadata_handles()->remove_at(i); \
aoqi@0 111 } \
aoqi@0 112 } \
aoqi@0 113 inline name##Handle::~name##Handle () { remove(); } \
aoqi@0 114
aoqi@0 115 DEF_METADATA_HANDLE_FN(method, Method)
aoqi@0 116 DEF_METADATA_HANDLE_FN(constantPool, ConstantPool)
aoqi@0 117
aoqi@0 118 inline HandleMark::HandleMark() {
aoqi@0 119 initialize(Thread::current());
aoqi@0 120 }
aoqi@0 121
aoqi@0 122
aoqi@0 123 inline void HandleMark::push() {
aoqi@0 124 // This is intentionally a NOP. pop_and_restore will reset
aoqi@0 125 // values to the HandleMark further down the stack, typically
aoqi@0 126 // in JavaCalls::call_helper.
aoqi@0 127 debug_only(_area->_handle_mark_nesting++);
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 inline void HandleMark::pop_and_restore() {
aoqi@0 131 HandleArea* area = _area; // help compilers with poor alias analysis
aoqi@0 132 // Delete later chunks
aoqi@0 133 if( _chunk->next() ) {
aoqi@0 134 // reset arena size before delete chunks. Otherwise, the total
aoqi@0 135 // arena size could exceed total chunk size
aoqi@0 136 assert(area->size_in_bytes() > size_in_bytes(), "Sanity check");
aoqi@0 137 area->set_size_in_bytes(size_in_bytes());
aoqi@0 138 _chunk->next_chop();
aoqi@0 139 } else {
aoqi@0 140 assert(area->size_in_bytes() == size_in_bytes(), "Sanity check");
aoqi@0 141 }
aoqi@0 142 // Roll back arena to saved top markers
aoqi@0 143 area->_chunk = _chunk;
aoqi@0 144 area->_hwm = _hwm;
aoqi@0 145 area->_max = _max;
aoqi@0 146 debug_only(area->_handle_mark_nesting--);
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 #endif // SHARE_VM_RUNTIME_HANDLES_INLINE_HPP

mercurial