duke@435: /* hseigel@5528: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_OOPS_KLASS_INLINE_HPP stefank@2314: #define SHARE_VM_OOPS_KLASS_INLINE_HPP stefank@2314: hseigel@5528: #include "memory/universe.hpp" stefank@2314: #include "oops/klass.hpp" stefank@2314: #include "oops/markOop.hpp" stefank@2314: duke@435: inline void Klass::set_prototype_header(markOop header) { duke@435: assert(!header->has_bias_pattern() || oop_is_instance(), "biased locking currently only supported for Java instances"); duke@435: _prototype_header = header; duke@435: } stefank@2314: hseigel@5528: inline bool Klass::is_null(Klass* obj) { return obj == NULL; } hseigel@5528: inline bool Klass::is_null(narrowKlass obj) { return obj == 0; } hseigel@5528: hseigel@5528: // Encoding and decoding for klass field. hseigel@5528: hseigel@5528: inline bool check_klass_alignment(Klass* obj) { hseigel@5528: return (intptr_t)obj % KlassAlignmentInBytes == 0; hseigel@5528: } hseigel@5528: hseigel@5528: inline narrowKlass Klass::encode_klass_not_null(Klass* v) { hseigel@5528: assert(!is_null(v), "klass value can never be zero"); hseigel@5528: assert(check_klass_alignment(v), "Address not aligned"); hseigel@5528: int shift = Universe::narrow_klass_shift(); hseigel@5528: uint64_t pd = (uint64_t)(pointer_delta((void*)v, Universe::narrow_klass_base(), 1)); hseigel@5528: assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding"); hseigel@5528: uint64_t result = pd >> shift; hseigel@5528: assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow"); hseigel@5528: assert(decode_klass(result) == v, "reversibility"); hseigel@5528: return (narrowKlass)result; hseigel@5528: } hseigel@5528: hseigel@5528: inline narrowKlass Klass::encode_klass(Klass* v) { hseigel@5528: return is_null(v) ? (narrowKlass)0 : encode_klass_not_null(v); hseigel@5528: } hseigel@5528: hseigel@5528: inline Klass* Klass::decode_klass_not_null(narrowKlass v) { hseigel@5528: assert(!is_null(v), "narrow klass value can never be zero"); hseigel@5528: int shift = Universe::narrow_klass_shift(); hseigel@5528: Klass* result = (Klass*)(void*)((uintptr_t)Universe::narrow_klass_base() + ((uintptr_t)v << shift)); hseigel@5528: assert(check_klass_alignment(result), err_msg("address not aligned: " PTR_FORMAT, (void*) result)); hseigel@5528: return result; hseigel@5528: } hseigel@5528: hseigel@5528: inline Klass* Klass::decode_klass(narrowKlass v) { hseigel@5528: return is_null(v) ? (Klass*)NULL : decode_klass_not_null(v); hseigel@5528: } hseigel@5528: stefank@2314: #endif // SHARE_VM_OOPS_KLASS_INLINE_HPP