2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_RUNTIME_STUBCODEGENERATOR_HPP
|
|
|
|
#define SHARE_RUNTIME_STUBCODEGENERATOR_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#include "asm/assembler.hpp"
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
|
2016-02-15 20:26:02 +03:00
|
|
|
// All the basic framework for stub code generation/debugging/printing.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
// A StubCodeDesc describes a piece of generated code (usually stubs).
|
|
|
|
// This information is mainly useful for debugging and printing.
|
|
|
|
// Currently, code descriptors are simply chained in a linked list,
|
|
|
|
// this may have to change if searching becomes too slow.
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class StubCodeDesc: public CHeapObj<mtCode> {
|
2016-02-15 20:26:02 +03:00
|
|
|
private:
|
2007-12-01 00:00:00 +00:00
|
|
|
static StubCodeDesc* _list; // the list of all descriptors
|
2016-02-15 20:26:02 +03:00
|
|
|
static bool _frozen; // determines whether _list modifications are allowed
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
StubCodeDesc* _next; // the next element in the linked list
|
|
|
|
const char* _group; // the group to which the stub code belongs
|
|
|
|
const char* _name; // the name assigned to the stub code
|
|
|
|
address _begin; // points to the first byte of the stub code (included)
|
|
|
|
address _end; // points to the first byte after the stub code (excluded)
|
|
|
|
|
|
|
|
void set_end(address end) {
|
|
|
|
assert(_begin <= end, "begin & end not properly ordered");
|
|
|
|
_end = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_begin(address begin) {
|
|
|
|
assert(begin >= _begin, "begin may not decrease");
|
|
|
|
assert(_end == NULL || begin <= _end, "begin & end not properly ordered");
|
|
|
|
_begin = begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class StubCodeMark;
|
|
|
|
friend class StubCodeGenerator;
|
|
|
|
|
|
|
|
public:
|
2016-02-19 20:41:36 +03:00
|
|
|
static StubCodeDesc* first() { return _list; }
|
|
|
|
static StubCodeDesc* next(StubCodeDesc* desc) { return desc->_next; }
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
static StubCodeDesc* desc_for(address pc); // returns the code descriptor for the code containing pc or NULL
|
|
|
|
static const char* name_for(address pc); // returns the name of the code containing pc or NULL
|
|
|
|
|
2015-07-01 10:53:26 +02:00
|
|
|
StubCodeDesc(const char* group, const char* name, address begin, address end = NULL) {
|
2016-02-15 20:26:02 +03:00
|
|
|
assert(!_frozen, "no modifications allowed");
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(name != NULL, "no name specified");
|
|
|
|
_next = _list;
|
|
|
|
_group = group;
|
|
|
|
_name = name;
|
|
|
|
_begin = begin;
|
2015-07-01 10:53:26 +02:00
|
|
|
_end = end;
|
2007-12-01 00:00:00 +00:00
|
|
|
_list = this;
|
|
|
|
};
|
|
|
|
|
2016-02-15 20:26:02 +03:00
|
|
|
static void freeze();
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
const char* group() const { return _group; }
|
|
|
|
const char* name() const { return _name; }
|
|
|
|
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; }
|
2010-08-03 08:13:38 -04:00
|
|
|
void print_on(outputStream* st) const;
|
2019-05-10 09:05:29 -04:00
|
|
|
void print() const;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The base class for all stub-generating code generators.
|
|
|
|
// Provides utility functions.
|
|
|
|
|
|
|
|
class StubCodeGenerator: public StackObj {
|
2016-02-19 20:41:36 +03:00
|
|
|
private:
|
|
|
|
bool _print_code;
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
protected:
|
|
|
|
MacroAssembler* _masm;
|
|
|
|
|
|
|
|
public:
|
2011-06-14 14:41:33 -07:00
|
|
|
StubCodeGenerator(CodeBuffer* code, bool print_code = false);
|
2007-12-01 00:00:00 +00:00
|
|
|
~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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Stack-allocated helper class used to associate a stub code with a name.
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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 {
|
2016-02-15 20:26:02 +03:00
|
|
|
private:
|
2007-12-01 00:00:00 +00:00
|
|
|
StubCodeGenerator* _cgen;
|
|
|
|
StubCodeDesc* _cdesc;
|
|
|
|
|
|
|
|
public:
|
|
|
|
StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name);
|
|
|
|
~StubCodeMark();
|
|
|
|
|
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_RUNTIME_STUBCODEGENERATOR_HPP
|