src/share/vm/runtime/stubCodeGenerator.hpp

Wed, 09 Apr 2008 15:10:22 -0700

author
rasbold
date
Wed, 09 Apr 2008 15:10:22 -0700
changeset 544
9f4457a14b58
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

Merge

duke@435 1 /*
duke@435 2 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // All the basic framework for stubcode generation/debugging/printing.
duke@435 26
duke@435 27
duke@435 28 // A StubCodeDesc describes a piece of generated code (usually stubs).
duke@435 29 // This information is mainly useful for debugging and printing.
duke@435 30 // Currently, code descriptors are simply chained in a linked list,
duke@435 31 // this may have to change if searching becomes too slow.
duke@435 32
duke@435 33 class StubCodeDesc: public CHeapObj {
duke@435 34 protected:
duke@435 35 static StubCodeDesc* _list; // the list of all descriptors
duke@435 36 static int _count; // length of list
duke@435 37
duke@435 38 StubCodeDesc* _next; // the next element in the linked list
duke@435 39 const char* _group; // the group to which the stub code belongs
duke@435 40 const char* _name; // the name assigned to the stub code
duke@435 41 int _index; // serial number assigned to the stub
duke@435 42 address _begin; // points to the first byte of the stub code (included)
duke@435 43 address _end; // points to the first byte after the stub code (excluded)
duke@435 44
duke@435 45 void set_end(address end) {
duke@435 46 assert(_begin <= end, "begin & end not properly ordered");
duke@435 47 _end = end;
duke@435 48 }
duke@435 49
duke@435 50 void set_begin(address begin) {
duke@435 51 assert(begin >= _begin, "begin may not decrease");
duke@435 52 assert(_end == NULL || begin <= _end, "begin & end not properly ordered");
duke@435 53 _begin = begin;
duke@435 54 }
duke@435 55
duke@435 56 friend class StubCodeMark;
duke@435 57 friend class StubCodeGenerator;
duke@435 58
duke@435 59 public:
duke@435 60 static StubCodeDesc* desc_for(address pc); // returns the code descriptor for the code containing pc or NULL
duke@435 61 static StubCodeDesc* desc_for_index(int); // returns the code descriptor for the index or NULL
duke@435 62 static const char* name_for(address pc); // returns the name of the code containing pc or NULL
duke@435 63
duke@435 64 StubCodeDesc(const char* group, const char* name, address begin) {
duke@435 65 assert(name != NULL, "no name specified");
duke@435 66 _next = _list;
duke@435 67 _group = group;
duke@435 68 _name = name;
duke@435 69 _index = ++_count; // (never zero)
duke@435 70 _begin = begin;
duke@435 71 _end = NULL;
duke@435 72 _list = this;
duke@435 73 };
duke@435 74
duke@435 75 const char* group() const { return _group; }
duke@435 76 const char* name() const { return _name; }
duke@435 77 int index() const { return _index; }
duke@435 78 address begin() const { return _begin; }
duke@435 79 address end() const { return _end; }
duke@435 80 int size_in_bytes() const { return _end - _begin; }
duke@435 81 bool contains(address pc) const { return _begin <= pc && pc < _end; }
duke@435 82 void print();
duke@435 83 };
duke@435 84
duke@435 85 // The base class for all stub-generating code generators.
duke@435 86 // Provides utility functions.
duke@435 87
duke@435 88 class StubCodeGenerator: public StackObj {
duke@435 89 protected:
duke@435 90 MacroAssembler* _masm;
duke@435 91
duke@435 92 StubCodeDesc* _first_stub;
duke@435 93 StubCodeDesc* _last_stub;
duke@435 94
duke@435 95 public:
duke@435 96 StubCodeGenerator(CodeBuffer* code);
duke@435 97 ~StubCodeGenerator();
duke@435 98
duke@435 99 MacroAssembler* assembler() const { return _masm; }
duke@435 100
duke@435 101 virtual void stub_prolog(StubCodeDesc* cdesc); // called by StubCodeMark constructor
duke@435 102 virtual void stub_epilog(StubCodeDesc* cdesc); // called by StubCodeMark destructor
duke@435 103 };
duke@435 104
duke@435 105
duke@435 106 // Stack-allocated helper class used to assciate a stub code with a name.
duke@435 107 // All stub code generating functions that use a StubCodeMark will be registered
duke@435 108 // in the global StubCodeDesc list and the generated stub code can be identified
duke@435 109 // later via an address pointing into it.
duke@435 110
duke@435 111 class StubCodeMark: public StackObj {
duke@435 112 protected:
duke@435 113 StubCodeGenerator* _cgen;
duke@435 114 StubCodeDesc* _cdesc;
duke@435 115
duke@435 116 public:
duke@435 117 StubCodeMark(StubCodeGenerator* cgen, const char* group, const char* name);
duke@435 118 ~StubCodeMark();
duke@435 119
duke@435 120 };

mercurial