1 /*
2 * Copyright (c) 2018, 2020, 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_OOPS_CPCACHE_INLINE_HPP
26 #define SHARE_OOPS_CPCACHE_INLINE_HPP
27
28 #include "oops/cpCache.hpp"
29
30 #include "oops/oopHandle.inline.hpp"
31 #include "runtime/atomic.hpp"
32
indices_ord() const33 inline int ConstantPoolCacheEntry::indices_ord() const { return Atomic::load_acquire(&_indices); }
34
bytecode_1() const35 inline Bytecodes::Code ConstantPoolCacheEntry::bytecode_1() const {
36 return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask);
37 }
38
bytecode_2() const39 inline Bytecodes::Code ConstantPoolCacheEntry::bytecode_2() const {
40 return Bytecodes::cast((indices_ord() >> bytecode_2_shift) & bytecode_2_mask);
41 }
42
43 // Has this bytecode been resolved? Only valid for invokes and get/put field/static.
is_resolved(Bytecodes::Code code) const44 inline bool ConstantPoolCacheEntry::is_resolved(Bytecodes::Code code) const {
45 switch (bytecode_number(code)) {
46 case 1: return (bytecode_1() == code);
47 case 2: return (bytecode_2() == code);
48 }
49 return false; // default: not resolved
50 }
51
f2_as_interface_method() const52 inline Method* ConstantPoolCacheEntry::f2_as_interface_method() const {
53 assert(bytecode_1() == Bytecodes::_invokeinterface, "");
54 return (Method*)_f2;
55 }
56
f1_ord() const57 inline Metadata* ConstantPoolCacheEntry::f1_ord() const { return (Metadata *)Atomic::load_acquire(&_f1); }
58
f1_as_method() const59 inline Method* ConstantPoolCacheEntry::f1_as_method() const {
60 Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), "");
61 return (Method*)f1;
62 }
63
f1_as_klass() const64 inline Klass* ConstantPoolCacheEntry::f1_as_klass() const {
65 Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), "");
66 return (Klass*)f1;
67 }
68
is_f1_null() const69 inline bool ConstantPoolCacheEntry::is_f1_null() const { Metadata* f1 = f1_ord(); return f1 == NULL; }
70
has_appendix() const71 inline bool ConstantPoolCacheEntry::has_appendix() const {
72 return (!is_f1_null()) && (_flags & (1 << has_appendix_shift)) != 0;
73 }
74
has_local_signature() const75 inline bool ConstantPoolCacheEntry::has_local_signature() const {
76 return (!is_f1_null()) && (_flags & (1 << has_local_signature_shift)) != 0;
77 }
78
flags_ord() const79 inline intx ConstantPoolCacheEntry::flags_ord() const { return (intx)Atomic::load_acquire(&_flags); }
80
indy_resolution_failed() const81 inline bool ConstantPoolCacheEntry::indy_resolution_failed() const {
82 intx flags = flags_ord();
83 return (flags & (1 << indy_resolution_failed_shift)) != 0;
84 }
85
86 // Constructor
ConstantPoolCache(int length,const intStack & inverse_index_map,const intStack & invokedynamic_inverse_index_map,const intStack & invokedynamic_references_map)87 inline ConstantPoolCache::ConstantPoolCache(int length,
88 const intStack& inverse_index_map,
89 const intStack& invokedynamic_inverse_index_map,
90 const intStack& invokedynamic_references_map) :
91 _length(length),
92 _constant_pool(NULL) {
93 CDS_JAVA_HEAP_ONLY(_archived_references_index = -1;)
94 initialize(inverse_index_map, invokedynamic_inverse_index_map,
95 invokedynamic_references_map);
96 for (int i = 0; i < length; i++) {
97 assert(entry_at(i)->is_f1_null(), "Failed to clear?");
98 }
99 }
100
resolved_references()101 inline oop ConstantPoolCache::resolved_references() { return _resolved_references.resolve(); }
102
103 #endif // SHARE_OOPS_CPCACHE_INLINE_HPP
104