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