src/share/vm/runtime/stubCodeGenerator.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9448
73d689add964
permissions
-rw-r--r--

Merge

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

mercurial