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