1 /*
  2  * Copyright (c) 2018, 2021, 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 
 33 inline int ConstantPoolCacheEntry::indices_ord() const { return Atomic::load_acquire(&_indices); }
 34 
 35 inline Bytecodes::Code ConstantPoolCacheEntry::bytecode_1() const {
 36   return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask);
 37 }
 38 
 39 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.
 44 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 
 52 inline Method* ConstantPoolCacheEntry::f2_as_interface_method() const {
 53   assert(bytecode_1() == Bytecodes::_invokeinterface, "");
 54   return (Method*)_f2;
 55 }
 56 
 57 inline Metadata* ConstantPoolCacheEntry::f1_ord() const { return (Metadata *)Atomic::load_acquire(&_f1); }
 58 
 59 inline Method* ConstantPoolCacheEntry::f1_as_method() const {
 60   Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), "");
 61   return (Method*)f1;
 62 }
 63 
 64 inline Klass* ConstantPoolCacheEntry::f1_as_klass() const {
 65   Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), "");
 66   return (Klass*)f1;
 67 }
 68 
 69 inline bool ConstantPoolCacheEntry::is_f1_null() const { Metadata* f1 = f1_ord(); return f1 == NULL; }
 70 
 71 inline bool ConstantPoolCacheEntry::has_appendix() const {
 72   return (!is_f1_null()) && (_flags & (1 << has_appendix_shift)) != 0;
 73 }
 74 
 75 inline bool ConstantPoolCacheEntry::has_local_signature() const {
 76   return (!is_f1_null()) && (_flags & (1 << has_local_signature_shift)) != 0;
 77 }
 78 
 79 inline intx ConstantPoolCacheEntry::flags_ord() const   { return (intx)Atomic::load_acquire(&_flags); }
 80 
 81 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
 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                                                   _marking_cycle(0) {
 94   CDS_JAVA_HEAP_ONLY(_archived_references_index = -1;)
 95   initialize(inverse_index_map, invokedynamic_inverse_index_map,
 96              invokedynamic_references_map);
 97   for (int i = 0; i < length; i++) {
 98     assert(entry_at(i)->is_f1_null(), "Failed to clear?");
 99   }
100 }
101 
102 inline oop ConstantPoolCache::resolved_references() { return _resolved_references.resolve(); }
103 
104 #endif // SHARE_OOPS_CPCACHE_INLINE_HPP