author | coleenp |
Wed, 24 Jul 2019 10:22:11 -0400 | |
changeset 57511 | 00ae3b739184 |
parent 54780 | f8d182aedc92 |
child 58015 | dd84de796f2c |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
1 |
/* |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
4 |
* |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
8 |
* |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
13 |
* accompanied this code). |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
14 |
* |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
18 |
* |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
21 |
* questions. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
22 |
* |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
23 |
*/ |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
24 |
|
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
25 |
#ifndef SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
26 |
#define SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
27 |
|
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
28 |
#include "gc/shared/collectedHeap.hpp" |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
29 |
#include "memory/universe.hpp" |
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
30 |
#include "oops/compressedOops.hpp" |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
31 |
#include "oops/oop.hpp" |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
32 |
|
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
33 |
// Functions for encoding and decoding compressed oops. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
34 |
// If the oops are compressed, the type passed to these overloaded functions |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
35 |
// is narrowOop. All functions are overloaded so they can be called by |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
36 |
// template functions without conditionals (the compiler instantiates via |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
37 |
// the right type and inlines the appropriate code). |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
38 |
|
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
39 |
// Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
40 |
// offset from the heap base. Saving the check for null can save instructions |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
41 |
// in inner GC loops so these are separated. |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
42 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
43 |
inline oop CompressedOops::decode_raw(narrowOop v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
44 |
return (oop)(void*)((uintptr_t)base() + ((uintptr_t)v << shift())); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
45 |
} |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
46 |
|
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
47 |
inline oop CompressedOops::decode_not_null(narrowOop v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
48 |
assert(!is_null(v), "narrow oop value can never be zero"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
49 |
oop result = decode_raw(v); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
50 |
assert(check_obj_alignment(result), "address not aligned: " INTPTR_FORMAT, p2i((void*) result)); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
51 |
return result; |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
52 |
} |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
53 |
|
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
54 |
inline oop CompressedOops::decode(narrowOop v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
55 |
return is_null(v) ? (oop)NULL : decode_not_null(v); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
56 |
} |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
57 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
58 |
inline narrowOop CompressedOops::encode_not_null(oop v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
59 |
assert(!is_null(v), "oop value can never be zero"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
60 |
assert(check_obj_alignment(v), "Address not aligned"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
61 |
assert(Universe::heap()->is_in_reserved(v), "Address not in heap"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
62 |
uint64_t pd = (uint64_t)(pointer_delta((void*)v, (void*)base(), 1)); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
63 |
assert(OopEncodingHeapMax > pd, "change encoding max if new encoding"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
64 |
uint64_t result = pd >> shift(); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
65 |
assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
66 |
assert(oopDesc::equals_raw(decode(result), v), "reversibility"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
67 |
return (narrowOop)result; |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
68 |
} |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
69 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
70 |
inline narrowOop CompressedOops::encode(oop v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
71 |
return is_null(v) ? (narrowOop)0 : encode_not_null(v); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
72 |
} |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
73 |
|
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
74 |
static inline bool check_alignment(Klass* v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
75 |
return (intptr_t)v % KlassAlignmentInBytes == 0; |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
76 |
} |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
77 |
|
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
78 |
inline Klass* CompressedKlassPointers::decode_raw(narrowKlass v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
79 |
return (Klass*)(void*)((uintptr_t)base() +((uintptr_t)v << shift())); |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
80 |
} |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
81 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
82 |
inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
83 |
assert(!is_null(v), "narrow klass value can never be zero"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
84 |
Klass* result = decode_raw(v); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
85 |
assert(check_alignment(result), "address not aligned: " INTPTR_FORMAT, p2i((void*) result)); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
86 |
return result; |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
87 |
} |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
88 |
|
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
89 |
inline Klass* CompressedKlassPointers::decode(narrowKlass v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
90 |
return is_null(v) ? (Klass*)NULL : decode_not_null(v); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
91 |
} |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
92 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
93 |
inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
94 |
assert(!is_null(v), "klass value can never be zero"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
95 |
assert(check_alignment(v), "Address not aligned"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
96 |
uint64_t pd = (uint64_t)(pointer_delta((void*)v, base(), 1)); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
97 |
assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
98 |
uint64_t result = pd >> shift(); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
99 |
assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
100 |
assert(decode(result) == v, "reversibility"); |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
101 |
return (narrowKlass)result; |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
102 |
} |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
103 |
|
54780
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
104 |
inline narrowKlass CompressedKlassPointers::encode(Klass* v) { |
f8d182aedc92
8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
52107
diff
changeset
|
105 |
return is_null(v) ? (narrowKlass)0 : encode_not_null(v); |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
106 |
} |
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
107 |
|
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
diff
changeset
|
108 |
#endif // SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP |