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