/* * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// The classes in this file provide a simple framework for the // management of little pieces of machine code - or stubs - // created on the fly and frequently discarded. In this frame- // work stubs are stored in a queue.
// Stub serves as abstract base class. A concrete stub // implementation is a subclass of Stub, implementing // all (non-virtual!) functions required sketched out // in the Stub class. // // A concrete stub layout may look like this (both data // and code sections could be empty as well): // // // stub -->|--------| <--+ <--- aligned by alignment() // | | | // | data | | // | | | // code_begin -->|--------| | <--- aligned by CodeEntryAlignment // | | | // | | | // | code | | size // | | | // | | | // code_end -->|--------| <--+ //
class Stub { public: // Initialization/finalization void initialize(int size) { ShouldNotCallThis(); } // called to initialize/specify the stub's size void finalize() { ShouldNotCallThis(); } // called before the stub is deallocated
// General info/converters int size() const { ShouldNotCallThis(); return 0; } // must return the size provided by initialize
// Code info
address code_begin() const { ShouldNotCallThis(); return NULL; } // points to the first byte of the code
address code_end() const { ShouldNotCallThis(); return NULL; } // points to the first byte after the code
// Debugging void verify() { ShouldNotCallThis(); } // verifies the Stub void print() { ShouldNotCallThis(); } // prints some information about the stub
};
// A stub interface defines the interface between a stub queue // and the stubs it queues. In order to avoid a vtable and // (and thus the extra word) in each stub, a concrete stub // interface object is created and associated with a stub // buffer which in turn uses the stub interface to interact // with its stubs. // // StubInterface serves as an abstract base class. A concrete // stub interface implementation is a subclass of StubInterface, // forwarding its virtual function calls to non-virtual calls // of the concrete stub (see also macro below). There's exactly // one stub interface instance required per stub queue.
class StubInterface: public CHeapObj<mtCode> { public: // Initialization/finalization virtualvoid initialize(Stub* self, int size) = 0; // called after creation (called twice if allocated via (request, commit)) virtualvoid finalize(Stub* self) = 0; // called before deallocation
// General info/converters virtualint size(Stub* self) const = 0; // the total size of the stub in bytes (must be a multiple of HeapWordSize) virtualint alignment() const = 0; // computes the alignment
// Code info virtual address code_begin(Stub* self) const = 0; // points to the first code byte virtual address code_end(Stub* self) const = 0; // points to the first byte after the code
// Debugging virtualvoid verify(Stub* self) = 0; // verifies the stub virtualvoid print(Stub* self) = 0; // prints information about the stub
};
// DEF_STUB_INTERFACE is used to create a concrete stub interface // class, forwarding stub interface calls to the corresponding // stub calls.
// A StubQueue maintains a queue of stubs. // Note: All sizes (spaces) are given in bytes.
class StubQueue: public CHeapObj<mtCode> { friendclass VMStructs; private:
StubInterface* _stub_interface; // the interface prototype
address _stub_buffer; // where all stubs are stored int _buffer_size; // the buffer size in bytes int _buffer_limit; // the (byte) index of the actual buffer limit (_buffer_limit <= _buffer_size) int _queue_begin; // the (byte) index of the first queue entry (word-aligned) int _queue_end; // the (byte) index of the first entry after the queue (word-aligned) int _number_of_stubs; // the number of buffered stubs
Mutex* const _mutex; // the lock used for a (request, commit) transaction
// Helpers int compute_stub_size(Stub* stub, int code_size);
public:
StubQueue(StubInterface* stub_interface, int buffer_size, Mutex* lock, constchar* name);
~StubQueue();
// General queue info bool is_empty() const { return _queue_begin == _queue_end; } int total_space() const { return _buffer_size - 1; } int available_space() const { int d = _queue_begin - _queue_end - 1; return d < 0 ? d + _buffer_size : d; } int used_space() const { return total_space() - available_space(); } int number_of_stubs() const { return _number_of_stubs; } bool contains(address pc) const { return _stub_buffer <= pc && pc < _stub_buffer + _buffer_limit; }
Stub* stub_containing(address pc) const;
address code_start() const { return _stub_buffer; }
address code_end() const { return _stub_buffer + _buffer_limit; }
// Stub allocation (atomic transactions)
Stub* request_committed(int code_size); // request a stub that provides exactly code_size space for code
Stub* request(int requested_code_size); // request a stub with a (maximum) code space - locks the queue void commit (int committed_code_size); // commit the previously requested stub - unlocks the queue
// Stub deallocation void remove_first(); // remove the first stub in the queue void remove_first(int n); // remove the first n stubs in the queue void remove_all(); // remove all stubs in the queue
void deallocate_unused_tail(); // deallocate the unused tail of the underlying CodeBlob // only used from TemplateInterpreter::initialize() // Iteration
Stub* first() const { return number_of_stubs() > 0 ? stub_at(_queue_begin) : NULL; }
Stub* next(Stub* s) const { int i = index_of(s) + stub_size(s); // Only wrap around in the non-contiguous case (see stubss.cpp) if (i == _buffer_limit && _queue_end < _buffer_limit) i = 0; return (i == _queue_end) ? NULL : stub_at(i);
}
// Debugging/printing void verify(); // verifies the stub queue void print(); // prints information about the stub queue
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.