1 /*
   2  * Copyright (c) 1998, 2017, 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_COMPILEDICHOLDEROOP_HPP
  26 #define SHARE_VM_OOPS_COMPILEDICHOLDEROOP_HPP
  27 
  28 #include "oops/oop.hpp"
  29 
  30 // A CompiledICHolder* is a helper object for the inline cache implementation.
  31 // It holds:
  32 //   (1) (method+klass pair) when converting from compiled to an interpreted call
  33 //   (2) (klass+klass pair) when calling itable stub from megamorphic compiled call
  34 //
  35 // These are always allocated in the C heap and are freed during a
  36 // safepoint by the ICBuffer logic.  It's unsafe to free them earlier
  37 // since they might be in use.
  38 //
  39 
  40 
  41 class CompiledICHolder : public CHeapObj<mtCompiler> {
  42   friend class VMStructs;
  43  private:
  44   static volatile int _live_count; // allocated
  45   static volatile int _live_not_claimed_count; // allocated but not yet in use so not
  46                                                // reachable by iterating over nmethods
  47 
  48   Metadata* _holder_metadata;
  49   Klass*    _holder_klass;    // to avoid name conflict with oopDesc::_klass
  50   CompiledICHolder* _next;
  51 
  52  public:
  53   // Constructor
  54   CompiledICHolder(Metadata* metadata, Klass* klass)
  55       : _holder_metadata(metadata), _holder_klass(klass) {
  56 #ifdef ASSERT
  57     Atomic::inc(&_live_count);
  58     Atomic::inc(&_live_not_claimed_count);
  59 #endif
  60   }
  61 
  62   ~CompiledICHolder() {
  63 #ifdef ASSERT
  64     assert(_live_count > 0, "underflow");
  65     Atomic::dec(&_live_count);
  66 #endif
  67   }
  68 
  69   static int live_count() { return _live_count; }
  70   static int live_not_claimed_count() { return _live_not_claimed_count; }
  71 
  72   // accessors
  73   Klass*    holder_klass()  const     { return _holder_klass; }
  74   Metadata* holder_metadata() const   { return _holder_metadata; }
  75 
  76   void set_holder_metadata(Metadata* m) { _holder_metadata = m; }
  77   void set_holder_klass(Klass* k)     { _holder_klass = k; }
  78 
  79   static int holder_metadata_offset() { return offset_of(CompiledICHolder, _holder_metadata); }
  80   static int holder_klass_offset()    { return offset_of(CompiledICHolder, _holder_klass); }
  81 
  82   CompiledICHolder* next()     { return _next; }
  83   void set_next(CompiledICHolder* n) { _next = n; }
  84 
  85   bool is_loader_alive(BoolObjectClosure* is_alive);
  86 
  87   // Verify
  88   void verify_on(outputStream* st);
  89 
  90   // Printing
  91   void print_on(outputStream* st) const;
  92   void print_value_on(outputStream* st) const;
  93 
  94   const char* internal_name() const { return "{compiledICHolder}"; }
  95 
  96   void claim() {
  97 #ifdef ASSERT
  98     Atomic::dec(&_live_not_claimed_count);
  99 #endif
 100   }
 101 };
 102 
 103 #endif // SHARE_VM_OOPS_COMPILEDICHOLDEROOP_HPP