aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP aoqi@0: #define SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP aoqi@0: aoqi@0: #include "asm/assembler.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: // All the basic framework for stubcode generation/debugging/printing. aoqi@0: aoqi@0: aoqi@0: // A StubCodeDesc describes a piece of generated code (usually stubs). aoqi@0: // This information is mainly useful for debugging and printing. aoqi@0: // Currently, code descriptors are simply chained in a linked list, aoqi@0: // this may have to change if searching becomes too slow. aoqi@0: aoqi@0: class StubCodeDesc: public CHeapObj { aoqi@0: protected: aoqi@0: static StubCodeDesc* _list; // the list of all descriptors aoqi@0: static int _count; // length of list aoqi@0: aoqi@0: StubCodeDesc* _next; // the next element in the linked list aoqi@0: const char* _group; // the group to which the stub code belongs aoqi@0: const char* _name; // the name assigned to the stub code aoqi@0: int _index; // serial number assigned to the stub aoqi@0: address _begin; // points to the first byte of the stub code (included) aoqi@0: address _end; // points to the first byte after the stub code (excluded) aoqi@0: aoqi@0: void set_end(address end) { aoqi@0: assert(_begin <= end, "begin & end not properly ordered"); aoqi@0: _end = end; aoqi@0: } aoqi@0: aoqi@0: void set_begin(address begin) { aoqi@0: assert(begin >= _begin, "begin may not decrease"); aoqi@0: assert(_end == NULL || begin <= _end, "begin & end not properly ordered"); aoqi@0: _begin = begin; aoqi@0: } aoqi@0: aoqi@0: friend class StubCodeMark; aoqi@0: friend class StubCodeGenerator; aoqi@0: aoqi@0: public: aoqi@0: static StubCodeDesc* desc_for(address pc); // returns the code descriptor for the code containing pc or NULL aoqi@0: static StubCodeDesc* desc_for_index(int); // returns the code descriptor for the index or NULL aoqi@0: static const char* name_for(address pc); // returns the name of the code containing pc or NULL aoqi@0: aoqi@0: StubCodeDesc(const char* group, const char* name, address begin) { aoqi@0: assert(name != NULL, "no name specified"); aoqi@0: _next = _list; aoqi@0: _group = group; aoqi@0: _name = name; aoqi@0: _index = ++_count; // (never zero) aoqi@0: _begin = begin; aoqi@0: _end = NULL; aoqi@0: _list = this; aoqi@0: }; aoqi@0: aoqi@0: const char* group() const { return _group; } aoqi@0: const char* name() const { return _name; } aoqi@0: int index() const { return _index; } aoqi@0: address begin() const { return _begin; } aoqi@0: address end() const { return _end; } aoqi@0: int size_in_bytes() const { return _end - _begin; } aoqi@0: bool contains(address pc) const { return _begin <= pc && pc < _end; } aoqi@0: void print_on(outputStream* st) const; aoqi@0: void print() const { print_on(tty); } aoqi@0: }; aoqi@0: aoqi@0: // The base class for all stub-generating code generators. aoqi@0: // Provides utility functions. aoqi@0: aoqi@0: class StubCodeGenerator: public StackObj { aoqi@0: protected: aoqi@0: MacroAssembler* _masm; aoqi@0: aoqi@0: StubCodeDesc* _first_stub; aoqi@0: StubCodeDesc* _last_stub; aoqi@0: bool _print_code; aoqi@0: aoqi@0: public: aoqi@0: StubCodeGenerator(CodeBuffer* code, bool print_code = false); aoqi@0: ~StubCodeGenerator(); aoqi@0: aoqi@0: MacroAssembler* assembler() const { return _masm; } aoqi@0: aoqi@0: virtual void stub_prolog(StubCodeDesc* cdesc); // called by StubCodeMark constructor aoqi@0: virtual void stub_epilog(StubCodeDesc* cdesc); // called by StubCodeMark destructor aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Stack-allocated helper class used to assciate a stub code with a name. aoqi@0: // All stub code generating functions that use a StubCodeMark will be registered aoqi@0: // in the global StubCodeDesc list and the generated stub code can be identified aoqi@0: // later via an address pointing into it. aoqi@0: aoqi@0: class StubCodeMark: public StackObj { aoqi@0: protected: aoqi@0: StubCodeGenerator* _cgen; aoqi@0: StubCodeDesc* _cdesc; aoqi@0: aoqi@0: public: aoqi@0: StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name); aoqi@0: ~StubCodeMark(); aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP