Path: blob/master/src/hotspot/share/jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp
41155 views
/*1* Copyright (c) 2019, 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_JFR_LEAKPROFILER_UTILITIES_UNIFIEDOOPREF_INLINE_HPP25#define SHARE_JFR_LEAKPROFILER_UTILITIES_UNIFIEDOOPREF_INLINE_HPP2627#include "jfr/leakprofiler/utilities/unifiedOopRef.hpp"2829#include "oops/access.inline.hpp"30#include "utilities/debug.hpp"3132template <typename T>33inline T UnifiedOopRef::addr() const {34return reinterpret_cast<T>(_value & ~uintptr_t(3));35}3637// Visual Studio 2019 and earlier have a problem with reinterpret_cast38// when the new type is the same as the expression type. For example:39// reinterpret_cast<int>(1);40// "error C2440: 'reinterpret_cast': cannot convert from 'int' to 'int'"41// this specialization provides a workaround.42template<>43inline uintptr_t UnifiedOopRef::addr<uintptr_t>() const {44return _value & ~uintptr_t(3);45}4647inline bool UnifiedOopRef::is_narrow() const {48return _value & 1;49}5051inline bool UnifiedOopRef::is_native() const {52return _value & 2;53}5455inline bool UnifiedOopRef::is_null() const {56return _value == 0;57}5859inline UnifiedOopRef UnifiedOopRef::encode_in_native(const narrowOop* ref) {60assert(ref != NULL, "invariant");61UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 3 };62assert(result.addr<narrowOop*>() == ref, "sanity");63return result;64}6566inline UnifiedOopRef UnifiedOopRef::encode_in_native(const oop* ref) {67assert(ref != NULL, "invariant");68UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 2 };69assert(result.addr<oop*>() == ref, "sanity");70return result;71}7273inline UnifiedOopRef UnifiedOopRef::encode_in_heap(const narrowOop* ref) {74assert(ref != NULL, "invariant");75UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 1 };76assert(result.addr<narrowOop*>() == ref, "sanity");77return result;78}7980inline UnifiedOopRef UnifiedOopRef::encode_in_heap(const oop* ref) {81assert(ref != NULL, "invariant");82UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 0 };83assert(result.addr<oop*>() == ref, "sanity");84return result;85}8687inline UnifiedOopRef UnifiedOopRef::encode_null() {88UnifiedOopRef result = { 0 };89return result;90}9192inline oop UnifiedOopRef::dereference() const {93if (is_native()) {94if (is_narrow()) {95return NativeAccess<AS_NO_KEEPALIVE>::oop_load(addr<narrowOop*>());96} else {97return NativeAccess<AS_NO_KEEPALIVE>::oop_load(addr<oop*>());98}99} else {100if (is_narrow()) {101return HeapAccess<AS_NO_KEEPALIVE>::oop_load(addr<narrowOop*>());102} else {103return HeapAccess<AS_NO_KEEPALIVE>::oop_load(addr<oop*>());104}105}106}107108#endif // SHARE_JFR_LEAKPROFILER_UTILITIES_UNIFIEDOOPREF_INLINE_HPP109110111