klass.inline.hpp revision 6412:53a41e7cbe05
1/*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef SHARE_VM_OOPS_KLASS_INLINE_HPP
26#define SHARE_VM_OOPS_KLASS_INLINE_HPP
27
28#include "memory/universe.hpp"
29#include "oops/klass.hpp"
30#include "oops/markOop.hpp"
31
32inline void Klass::set_prototype_header(markOop header) {
33  assert(!header->has_bias_pattern() || oop_is_instance(), "biased locking currently only supported for Java instances");
34  _prototype_header = header;
35}
36
37inline bool Klass::is_null(Klass* obj)  { return obj == NULL; }
38inline bool Klass::is_null(narrowKlass obj) { return obj == 0; }
39
40// Encoding and decoding for klass field.
41
42inline bool check_klass_alignment(Klass* obj) {
43  return (intptr_t)obj % KlassAlignmentInBytes == 0;
44}
45
46inline narrowKlass Klass::encode_klass_not_null(Klass* v) {
47  assert(!is_null(v), "klass value can never be zero");
48  assert(check_klass_alignment(v), "Address not aligned");
49  int    shift = Universe::narrow_klass_shift();
50  uint64_t pd = (uint64_t)(pointer_delta((void*)v, Universe::narrow_klass_base(), 1));
51  assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding");
52  uint64_t result = pd >> shift;
53  assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow");
54  assert(decode_klass(result) == v, "reversibility");
55  return (narrowKlass)result;
56}
57
58inline narrowKlass Klass::encode_klass(Klass* v) {
59  return is_null(v) ? (narrowKlass)0 : encode_klass_not_null(v);
60}
61
62inline Klass* Klass::decode_klass_not_null(narrowKlass v) {
63  assert(!is_null(v), "narrow klass value can never be zero");
64  int    shift = Universe::narrow_klass_shift();
65  Klass* result = (Klass*)(void*)((uintptr_t)Universe::narrow_klass_base() + ((uintptr_t)v << shift));
66  assert(check_klass_alignment(result), err_msg("address not aligned: " INTPTR_FORMAT, p2i((void*) result)));
67  return result;
68}
69
70inline Klass* Klass::decode_klass(narrowKlass v) {
71  return is_null(v) ? (Klass*)NULL : decode_klass_not_null(v);
72}
73
74#endif // SHARE_VM_OOPS_KLASS_INLINE_HPP
75