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