Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/oops/klass.inline.hpp
32285 views
/*1* Copyright (c) 2005, 2014, 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_OOPS_KLASS_INLINE_HPP25#define SHARE_VM_OOPS_KLASS_INLINE_HPP2627#include "memory/universe.hpp"28#include "oops/klass.hpp"29#include "oops/markOop.hpp"3031inline void Klass::set_prototype_header(markOop header) {32assert(!header->has_bias_pattern() || oop_is_instance(), "biased locking currently only supported for Java instances");33_prototype_header = header;34}3536inline bool Klass::is_null(Klass* obj) { return obj == NULL; }37inline bool Klass::is_null(narrowKlass obj) { return obj == 0; }3839// Encoding and decoding for klass field.4041inline bool check_klass_alignment(Klass* obj) {42return (intptr_t)obj % KlassAlignmentInBytes == 0;43}4445inline narrowKlass Klass::encode_klass_not_null(Klass* v) {46assert(!is_null(v), "klass value can never be zero");47assert(check_klass_alignment(v), "Address not aligned");48int shift = Universe::narrow_klass_shift();49uint64_t pd = (uint64_t)(pointer_delta((void*)v, Universe::narrow_klass_base(), 1));50assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding");51uint64_t result = pd >> shift;52assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow");53assert(decode_klass(result) == v, "reversibility");54return (narrowKlass)result;55}5657inline narrowKlass Klass::encode_klass(Klass* v) {58return is_null(v) ? (narrowKlass)0 : encode_klass_not_null(v);59}6061inline Klass* Klass::decode_klass_not_null(narrowKlass v) {62assert(!is_null(v), "narrow klass value can never be zero");63int shift = Universe::narrow_klass_shift();64Klass* result = (Klass*)(void*)((uintptr_t)Universe::narrow_klass_base() + ((uintptr_t)v << shift));65assert(check_klass_alignment(result), err_msg("address not aligned: " INTPTR_FORMAT, p2i((void*) result)));66return result;67}6869inline Klass* Klass::decode_klass(narrowKlass v) {70return is_null(v) ? (Klass*)NULL : decode_klass_not_null(v);71}7273#endif // SHARE_VM_OOPS_KLASS_INLINE_HPP747576