src/share/vm/code/stubs.hpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 6503
a9becfeecd1b
child 6876
710a3c8b516e
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

duke@435 1 /*
mikael@6198 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CODE_STUBS_HPP
stefank@2314 26 #define SHARE_VM_CODE_STUBS_HPP
stefank@2314 27
kvn@4107 28 #include "asm/codeBuffer.hpp"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 31 # include "os_linux.inline.hpp"
stefank@2314 32 #endif
stefank@2314 33 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 34 # include "os_solaris.inline.hpp"
stefank@2314 35 #endif
stefank@2314 36 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 37 # include "os_windows.inline.hpp"
stefank@2314 38 #endif
goetz@6461 39 #ifdef TARGET_OS_FAMILY_aix
goetz@6461 40 # include "os_aix.inline.hpp"
goetz@6461 41 #endif
never@3156 42 #ifdef TARGET_OS_FAMILY_bsd
never@3156 43 # include "os_bsd.inline.hpp"
never@3156 44 #endif
stefank@2314 45
duke@435 46 // The classes in this file provide a simple framework for the
duke@435 47 // management of little pieces of machine code - or stubs -
duke@435 48 // created on the fly and frequently discarded. In this frame-
duke@435 49 // work stubs are stored in a queue.
duke@435 50
duke@435 51
duke@435 52 // Stub serves as abstract base class. A concrete stub
duke@435 53 // implementation is a subclass of Stub, implementing
duke@435 54 // all (non-virtual!) functions required sketched out
duke@435 55 // in the Stub class.
duke@435 56 //
duke@435 57 // A concrete stub layout may look like this (both data
duke@435 58 // and code sections could be empty as well):
duke@435 59 //
duke@435 60 // ________
duke@435 61 // stub -->| | <--+
duke@435 62 // | data | |
duke@435 63 // |________| |
duke@435 64 // code_begin -->| | |
duke@435 65 // | | |
duke@435 66 // | code | | size
duke@435 67 // | | |
duke@435 68 // |________| |
duke@435 69 // code_end -->| | |
duke@435 70 // | data | |
duke@435 71 // |________| |
duke@435 72 // <--+
duke@435 73
duke@435 74
duke@435 75 class Stub VALUE_OBJ_CLASS_SPEC {
duke@435 76 public:
duke@435 77 // Initialization/finalization
kvn@4107 78 void initialize(int size,
roland@4767 79 CodeStrings& strings) { ShouldNotCallThis(); } // called to initialize/specify the stub's size
duke@435 80 void finalize() { ShouldNotCallThis(); } // called before the stub is deallocated
duke@435 81
duke@435 82 // General info/converters
duke@435 83 int size() const { ShouldNotCallThis(); return 0; } // must return the size provided by initialize
duke@435 84 static int code_size_to_size(int code_size) { ShouldNotCallThis(); return 0; } // computes the size given the code size
duke@435 85
duke@435 86 // Code info
duke@435 87 address code_begin() const { ShouldNotCallThis(); return NULL; } // points to the first byte of the code
duke@435 88 address code_end() const { ShouldNotCallThis(); return NULL; } // points to the first byte after the code
duke@435 89
duke@435 90 // Debugging
duke@435 91 void verify() { ShouldNotCallThis(); } // verifies the Stub
duke@435 92 void print() { ShouldNotCallThis(); } // prints some information about the stub
duke@435 93 };
duke@435 94
duke@435 95
duke@435 96 // A stub interface defines the interface between a stub queue
duke@435 97 // and the stubs it queues. In order to avoid a vtable and
duke@435 98 // (and thus the extra word) in each stub, a concrete stub
duke@435 99 // interface object is created and associated with a stub
duke@435 100 // buffer which in turn uses the stub interface to interact
duke@435 101 // with its stubs.
duke@435 102 //
duke@435 103 // StubInterface serves as an abstract base class. A concrete
duke@435 104 // stub interface implementation is a subclass of StubInterface,
duke@435 105 // forwarding its virtual function calls to non-virtual calls
duke@435 106 // of the concrete stub (see also macro below). There's exactly
duke@435 107 // one stub interface instance required per stub queue.
duke@435 108
zgu@3900 109 class StubInterface: public CHeapObj<mtCode> {
duke@435 110 public:
duke@435 111 // Initialization/finalization
kvn@4107 112 virtual void initialize(Stub* self, int size,
roland@4767 113 CodeStrings& strings) = 0; // called after creation (called twice if allocated via (request, commit))
duke@435 114 virtual void finalize(Stub* self) = 0; // called before deallocation
duke@435 115
duke@435 116 // General info/converters
duke@435 117 virtual int size(Stub* self) const = 0; // the total size of the stub in bytes (must be a multiple of CodeEntryAlignment)
duke@435 118 virtual int code_size_to_size(int code_size) const = 0; // computes the total stub size in bytes given the code size in bytes
duke@435 119
duke@435 120 // Code info
duke@435 121 virtual address code_begin(Stub* self) const = 0; // points to the first code byte
duke@435 122 virtual address code_end(Stub* self) const = 0; // points to the first byte after the code
duke@435 123
duke@435 124 // Debugging
duke@435 125 virtual void verify(Stub* self) = 0; // verifies the stub
duke@435 126 virtual void print(Stub* self) = 0; // prints information about the stub
duke@435 127 };
duke@435 128
duke@435 129
duke@435 130 // DEF_STUB_INTERFACE is used to create a concrete stub interface
duke@435 131 // class, forwarding stub interface calls to the corresponding
duke@435 132 // stub calls.
duke@435 133
duke@435 134 #define DEF_STUB_INTERFACE(stub) \
duke@435 135 class stub##Interface: public StubInterface { \
duke@435 136 private: \
duke@435 137 static stub* cast(Stub* self) { return (stub*)self; } \
duke@435 138 \
duke@435 139 public: \
duke@435 140 /* Initialization/finalization */ \
kvn@4107 141 virtual void initialize(Stub* self, int size, \
roland@4767 142 CodeStrings& strings) { cast(self)->initialize(size, strings); } \
duke@435 143 virtual void finalize(Stub* self) { cast(self)->finalize(); } \
duke@435 144 \
duke@435 145 /* General info */ \
duke@435 146 virtual int size(Stub* self) const { return cast(self)->size(); } \
duke@435 147 virtual int code_size_to_size(int code_size) const { return stub::code_size_to_size(code_size); } \
duke@435 148 \
duke@435 149 /* Code info */ \
duke@435 150 virtual address code_begin(Stub* self) const { return cast(self)->code_begin(); } \
duke@435 151 virtual address code_end(Stub* self) const { return cast(self)->code_end(); } \
duke@435 152 \
duke@435 153 /* Debugging */ \
duke@435 154 virtual void verify(Stub* self) { cast(self)->verify(); } \
duke@435 155 virtual void print(Stub* self) { cast(self)->print(); } \
duke@435 156 };
duke@435 157
duke@435 158
duke@435 159 // A StubQueue maintains a queue of stubs.
duke@435 160 // Note: All sizes (spaces) are given in bytes.
duke@435 161
zgu@3900 162 class StubQueue: public CHeapObj<mtCode> {
duke@435 163 friend class VMStructs;
duke@435 164 private:
duke@435 165 StubInterface* _stub_interface; // the interface prototype
duke@435 166 address _stub_buffer; // where all stubs are stored
duke@435 167 int _buffer_size; // the buffer size in bytes
duke@435 168 int _buffer_limit; // the (byte) index of the actual buffer limit (_buffer_limit <= _buffer_size)
duke@435 169 int _queue_begin; // the (byte) index of the first queue entry (word-aligned)
duke@435 170 int _queue_end; // the (byte) index of the first entry after the queue (word-aligned)
duke@435 171 int _number_of_stubs; // the number of buffered stubs
duke@435 172 Mutex* const _mutex; // the lock used for a (request, commit) transaction
duke@435 173
duke@435 174 void check_index(int i) const { assert(0 <= i && i < _buffer_limit && i % CodeEntryAlignment == 0, "illegal index"); }
duke@435 175 bool is_contiguous() const { return _queue_begin <= _queue_end; }
duke@435 176 int index_of(Stub* s) const { int i = (address)s - _stub_buffer; check_index(i); return i; }
duke@435 177 Stub* stub_at(int i) const { check_index(i); return (Stub*)(_stub_buffer + i); }
duke@435 178 Stub* current_stub() const { return stub_at(_queue_end); }
duke@435 179
duke@435 180 // Stub functionality accessed via interface
kvn@4107 181 void stub_initialize(Stub* s, int size,
roland@4767 182 CodeStrings& strings) { assert(size % CodeEntryAlignment == 0, "size not aligned"); _stub_interface->initialize(s, size, strings); }
duke@435 183 void stub_finalize(Stub* s) { _stub_interface->finalize(s); }
duke@435 184 int stub_size(Stub* s) const { return _stub_interface->size(s); }
duke@435 185 bool stub_contains(Stub* s, address pc) const { return _stub_interface->code_begin(s) <= pc && pc < _stub_interface->code_end(s); }
duke@435 186 int stub_code_size_to_size(int code_size) const { return _stub_interface->code_size_to_size(code_size); }
duke@435 187 void stub_verify(Stub* s) { _stub_interface->verify(s); }
duke@435 188 void stub_print(Stub* s) { _stub_interface->print(s); }
duke@435 189
duke@435 190 static void register_queue(StubQueue*);
duke@435 191
duke@435 192 public:
duke@435 193 StubQueue(StubInterface* stub_interface, int buffer_size, Mutex* lock,
duke@435 194 const char* name);
duke@435 195 ~StubQueue();
duke@435 196
duke@435 197 // General queue info
duke@435 198 bool is_empty() const { return _queue_begin == _queue_end; }
duke@435 199 int total_space() const { return _buffer_size - 1; }
duke@435 200 int available_space() const { int d = _queue_begin - _queue_end - 1; return d < 0 ? d + _buffer_size : d; }
duke@435 201 int used_space() const { return total_space() - available_space(); }
duke@435 202 int number_of_stubs() const { return _number_of_stubs; }
duke@435 203 bool contains(address pc) const { return _stub_buffer <= pc && pc < _stub_buffer + _buffer_limit; }
duke@435 204 Stub* stub_containing(address pc) const;
duke@435 205 address code_start() const { return _stub_buffer; }
duke@435 206 address code_end() const { return _stub_buffer + _buffer_limit; }
duke@435 207
duke@435 208 // Stub allocation (atomic transactions)
duke@435 209 Stub* request_committed(int code_size); // request a stub that provides exactly code_size space for code
duke@435 210 Stub* request(int requested_code_size); // request a stub with a (maximum) code space - locks the queue
kvn@4107 211 void commit (int committed_code_size,
roland@4767 212 CodeStrings& strings); // commit the previously requested stub - unlocks the queue
duke@435 213
duke@435 214 // Stub deallocation
duke@435 215 void remove_first(); // remove the first stub in the queue
duke@435 216 void remove_first(int n); // remove the first n stubs in the queue
duke@435 217 void remove_all(); // remove all stubs in the queue
duke@435 218
duke@435 219 // Iteration
duke@435 220 static void queues_do(void f(StubQueue* s)); // call f with each StubQueue
duke@435 221 void stubs_do(void f(Stub* s)); // call f with all stubs
duke@435 222 Stub* first() const { return number_of_stubs() > 0 ? stub_at(_queue_begin) : NULL; }
duke@435 223 Stub* next(Stub* s) const { int i = index_of(s) + stub_size(s);
duke@435 224 if (i == _buffer_limit) i = 0;
duke@435 225 return (i == _queue_end) ? NULL : stub_at(i);
duke@435 226 }
duke@435 227
duke@435 228 address stub_code_begin(Stub* s) const { return _stub_interface->code_begin(s); }
duke@435 229 address stub_code_end(Stub* s) const { return _stub_interface->code_end(s); }
duke@435 230
duke@435 231 // Debugging/printing
duke@435 232 void verify(); // verifies the stub queue
duke@435 233 void print(); // prints information about the stub queue
duke@435 234 };
stefank@2314 235
stefank@2314 236 #endif // SHARE_VM_CODE_STUBS_HPP

mercurial