stubs.hpp revision 4016
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith/*
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith *
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * This code is free software; you can redistribute it and/or modify it
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * under the terms of the GNU General Public License version 2 only, as
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * published by the Free Software Foundation.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith *
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * This code is distributed in the hope that it will be useful, but WITHOUT
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * version 2 for more details (a copy is included in the LICENSE file that
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * accompanied this code).
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith *
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * You should have received a copy of the GNU General Public License version
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * 2 along with this work; if not, write to the Free Software Foundation,
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith *
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * or visit www.oracle.com if you need additional information or have any
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith * questions.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith *
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith */
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#ifndef SHARE_VM_CODE_STUBS_HPP
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#define SHARE_VM_CODE_STUBS_HPP
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#include "asm/codeBuffer.hpp"
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#include "memory/allocation.hpp"
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#ifdef TARGET_OS_FAMILY_linux
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith# include "os_linux.inline.hpp"
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#endif
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#ifdef TARGET_OS_FAMILY_solaris
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith# include "os_solaris.inline.hpp"
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#endif
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#ifdef TARGET_OS_FAMILY_windows
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith# include "os_windows.inline.hpp"
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#endif
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#ifdef TARGET_OS_FAMILY_bsd
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith# include "os_bsd.inline.hpp"
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#endif
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// The classes in this file provide a simple framework for the
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// management of little pieces of machine code - or stubs -
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// created on the fly and frequently discarded. In this frame-
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// work stubs are stored in a queue.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// Stub serves as abstract base class. A concrete stub
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// implementation is a subclass of Stub, implementing
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// all (non-virtual!) functions required sketched out
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// in the Stub class.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith//
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// A concrete stub layout may look like this (both data
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// and code sections could be empty as well):
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith//
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// ________
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// stub -->| | <--+
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// | data | |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// |________| |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// code_begin -->| | |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// | | |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// | code | | size
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// | | |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// |________| |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// code_end -->| | |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// | data | |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// |________| |
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// <--+
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smithclass Stub VALUE_OBJ_CLASS_SPEC {
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith public:
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // Initialization/finalization
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void initialize(int size,
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith CodeComments& comments) { ShouldNotCallThis(); } // called to initialize/specify the stub's size
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith void finalize() { ShouldNotCallThis(); } // called before the stub is deallocated
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // General info/converters
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int size() const { ShouldNotCallThis(); return 0; } // must return the size provided by initialize
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith static int code_size_to_size(int code_size) { ShouldNotCallThis(); return 0; } // computes the size given the code size
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith // Code info
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith address code_begin() const { ShouldNotCallThis(); return NULL; } // points to the first byte of the code
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith address code_end() const { ShouldNotCallThis(); return NULL; } // points to the first byte after the code
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith // Debugging
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith void verify() { ShouldNotCallThis(); } // verifies the Stub
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith void print() { ShouldNotCallThis(); } // prints some information about the stub
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith};
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith// A stub interface defines the interface between a stub queue
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith// and the stubs it queues. In order to avoid a vtable and
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith// (and thus the extra word) in each stub, a concrete stub
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith// interface object is created and associated with a stub
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith// buffer which in turn uses the stub interface to interact
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith// with its stubs.
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith//
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith// StubInterface serves as an abstract base class. A concrete
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith// stub interface implementation is a subclass of StubInterface,
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith// forwarding its virtual function calls to non-virtual calls
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith// of the concrete stub (see also macro below). There's exactly
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// one stub interface instance required per stub queue.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smithclass StubInterface: public CHeapObj<mtCode> {
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith public:
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // Initialization/finalization
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void initialize(Stub* self, int size,
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith CodeComments& comments) = 0; // called after creation (called twice if allocated via (request, commit))
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void finalize(Stub* self) = 0; // called before deallocation
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // General info/converters
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual int size(Stub* self) const = 0; // the total size of the stub in bytes (must be a multiple of CodeEntryAlignment)
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual int code_size_to_size(int code_size) const = 0; // computes the total stub size in bytes given the code size in bytes
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // Code info
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith virtual address code_begin(Stub* self) const = 0; // points to the first code byte
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith virtual address code_end(Stub* self) const = 0; // points to the first byte after the code
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith // Debugging
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith virtual void verify(Stub* self) = 0; // verifies the stub
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void print(Stub* self) = 0; // prints information about the stub
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith};
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// DEF_STUB_INTERFACE is used to create a concrete stub interface
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// class, forwarding stub interface calls to the corresponding
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// stub calls.
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith#define DEF_STUB_INTERFACE(stub) \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith class stub##Interface: public StubInterface { \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith private: \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith static stub* cast(Stub* self) { return (stub*)self; } \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith public: \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith /* Initialization/finalization */ \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void initialize(Stub* self, int size, \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith CodeComments& comments) { cast(self)->initialize(size, comments); } \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void finalize(Stub* self) { cast(self)->finalize(); } \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith /* General info */ \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual int size(Stub* self) const { return cast(self)->size(); } \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual int code_size_to_size(int code_size) const { return stub::code_size_to_size(code_size); } \
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith \
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith /* Code info */ \
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith virtual address code_begin(Stub* self) const { return cast(self)->code_begin(); } \
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith virtual address code_end(Stub* self) const { return cast(self)->code_end(); } \
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith /* Debugging */ \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void verify(Stub* self) { cast(self)->verify(); } \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith virtual void print(Stub* self) { cast(self)->print(); } \
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith };
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith// A StubQueue maintains a queue of stubs.
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith// Note: All sizes (spaces) are given in bytes.
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smithclass StubQueue: public CHeapObj<mtCode> {
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith friend class VMStructs;
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith private:
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith StubInterface* _stub_interface; // the interface prototype
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith address _stub_buffer; // where all stubs are stored
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith int _buffer_size; // the buffer size in bytes
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith int _buffer_limit; // the (byte) index of the actual buffer limit (_buffer_limit <= _buffer_size)
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int _queue_begin; // the (byte) index of the first queue entry (word-aligned)
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int _queue_end; // the (byte) index of the first entry after the queue (word-aligned)
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int _number_of_stubs; // the number of buffered stubs
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith Mutex* const _mutex; // the lock used for a (request, commit) transaction
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void check_index(int i) const { assert(0 <= i && i < _buffer_limit && i % CodeEntryAlignment == 0, "illegal index"); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith bool is_contiguous() const { return _queue_begin <= _queue_end; }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int index_of(Stub* s) const { int i = (address)s - _stub_buffer; check_index(i); return i; }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith Stub* stub_at(int i) const { check_index(i); return (Stub*)(_stub_buffer + i); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith Stub* current_stub() const { return stub_at(_queue_end); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // Stub functionality accessed via interface
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void stub_initialize(Stub* s, int size,
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith CodeComments& comments) { assert(size % CodeEntryAlignment == 0, "size not aligned"); _stub_interface->initialize(s, size, comments); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void stub_finalize(Stub* s) { _stub_interface->finalize(s); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int stub_size(Stub* s) const { return _stub_interface->size(s); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith bool stub_contains(Stub* s, address pc) const { return _stub_interface->code_begin(s) <= pc && pc < _stub_interface->code_end(s); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int stub_code_size_to_size(int code_size) const { return _stub_interface->code_size_to_size(code_size); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void stub_verify(Stub* s) { _stub_interface->verify(s); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void stub_print(Stub* s) { _stub_interface->print(s); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith static void register_queue(StubQueue*);
f5443cec5378e1eba162c289f05b690b699c9c7bLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith public:
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith StubQueue(StubInterface* stub_interface, int buffer_size, Mutex* lock,
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith const char* name);
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith ~StubQueue();
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith // General queue info
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith bool is_empty() const { return _queue_begin == _queue_end; }
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith int total_space() const { return _buffer_size - 1; }
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith int available_space() const { int d = _queue_begin - _queue_end - 1; return d < 0 ? d + _buffer_size : d; }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int used_space() const { return total_space() - available_space(); }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith int number_of_stubs() const { return _number_of_stubs; }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith bool contains(address pc) const { return _stub_buffer <= pc && pc < _stub_buffer + _buffer_limit; }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith Stub* stub_containing(address pc) const;
f5443cec5378e1eba162c289f05b690b699c9c7bLuke Smith address code_start() const { return _stub_buffer; }
f5443cec5378e1eba162c289f05b690b699c9c7bLuke Smith address code_end() const { return _stub_buffer + _buffer_limit; }
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith // Stub allocation (atomic transactions)
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith Stub* request_committed(int code_size); // request a stub that provides exactly code_size space for code
f5443cec5378e1eba162c289f05b690b699c9c7bLuke Smith Stub* request(int requested_code_size); // request a stub with a (maximum) code space - locks the queue
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith void commit (int committed_code_size,
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith CodeComments& comments); // commit the previously requested stub - unlocks the queue
59c94cbcd6e39e484a57bf3665a8ab98beafc57eLuke Smith
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith // Stub deallocation
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith void remove_first(); // remove the first stub in the queue
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith void remove_first(int n); // remove the first n stubs in the queue
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith void remove_all(); // remove all stubs in the queue
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith // Iteration
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith static void queues_do(void f(StubQueue* s)); // call f with each StubQueue
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith void stubs_do(void f(Stub* s)); // call f with all stubs
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith Stub* first() const { return number_of_stubs() > 0 ? stub_at(_queue_begin) : NULL; }
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith Stub* next(Stub* s) const { int i = index_of(s) + stub_size(s);
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith if (i == _buffer_limit) i = 0;
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith return (i == _queue_end) ? NULL : stub_at(i);
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith }
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith address stub_code_begin(Stub* s) const { return _stub_interface->code_begin(s); }
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith address stub_code_end(Stub* s) const { return _stub_interface->code_end(s); }
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith // Debugging/printing
4eafc0c9b36f7e8efc8808ab27dbed7ff8dc87abLuke Smith void verify(); // verifies the stub queue
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith void print(); // prints information about the stub queue
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith};
32624ce45f113c04dfa5469b3cc77df42c4c46f4Luke Smith
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith#endif // SHARE_VM_CODE_STUBS_HPP
8fff801a4a38e13d6ff8181ff097fb01d058d617Luke Smith