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