annotate src/hotspot/share/classfile/bytecodeAssembler.hpp @ 54048:744dc9c33676

8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC Summary: Fixed typo in decorator name, variables, and comments. Reviewed-by: tschatzl
author kbarrett
date Mon, 11 Mar 2019 02:05:07 -0400
parents 601146c66cad
children
rev   line source
kamg@14385 1 /*
coleenp@53244 2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
kamg@14385 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kamg@14385 4 *
kamg@14385 5 * This code is free software; you can redistribute it and/or modify it
kamg@14385 6 * under the terms of the GNU General Public License version 2 only, as
kamg@14385 7 * published by the Free Software Foundation.
kamg@14385 8 *
kamg@14385 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kamg@14385 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kamg@14385 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kamg@14385 12 * version 2 for more details (a copy is included in the LICENSE file that
kamg@14385 13 * accompanied this code).
kamg@14385 14 *
kamg@14385 15 * You should have received a copy of the GNU General Public License version
kamg@14385 16 * 2 along with this work; if not, write to the Free Software Foundation,
kamg@14385 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kamg@14385 18 *
kamg@14385 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
kamg@14385 20 * or visit www.oracle.com if you need additional information or have any
kamg@14385 21 * questions.
kamg@14385 22 *
kamg@14385 23 */
kamg@14385 24
coleenp@53244 25 #ifndef SHARE_CLASSFILE_BYTECODEASSEMBLER_HPP
coleenp@53244 26 #define SHARE_CLASSFILE_BYTECODEASSEMBLER_HPP
kamg@14385 27
kamg@14385 28 #include "memory/allocation.hpp"
kamg@14385 29 #include "oops/method.hpp"
kamg@14385 30 #include "oops/symbol.hpp"
kamg@14385 31 #include "utilities/globalDefinitions.hpp"
kamg@14385 32 #include "utilities/growableArray.hpp"
kamg@14385 33 #include "utilities/resourceHash.hpp"
kamg@14385 34
kamg@14385 35
kamg@14385 36 /**
kamg@14385 37 * Bytecode Assembler
kamg@14385 38 *
kamg@14385 39 * These classes are used to synthesize code for creating new methods from
kamg@14385 40 * within the VM. This is only a partial implementation of an assembler;
kamg@14385 41 * only the bytecodes that are needed by clients are implemented at this time.
kamg@14385 42 * This is used during default method analysis to create overpass methods
kamg@14385 43 * and add them to a call during parsing. Other uses (such as creating
kamg@14385 44 * bridges) may come later. Any missing bytecodes can be implemented on an
kamg@14385 45 * as-need basis.
kamg@14385 46 */
kamg@14385 47
kamg@14385 48 class BytecodeBuffer : public GrowableArray<u1> {
kamg@14385 49 public:
kamg@14385 50 BytecodeBuffer() : GrowableArray<u1>(20) {}
kamg@14385 51 };
kamg@14385 52
kamg@14385 53 // Entries in a yet-to-be-created constant pool. Limited types for now.
coleenp@49364 54 class BytecodeCPEntry {
kamg@14385 55 public:
kamg@14385 56 enum tag {
kamg@14385 57 ERROR_TAG,
kamg@14385 58 UTF8,
kamg@14385 59 KLASS,
kamg@14385 60 STRING,
kamg@14385 61 NAME_AND_TYPE,
kamg@14385 62 METHODREF
kamg@14385 63 };
kamg@14385 64
kamg@14385 65 u1 _tag;
kamg@14385 66 union {
kamg@14385 67 Symbol* utf8;
kamg@14385 68 u2 klass;
kamg@14385 69 u2 string;
kamg@14385 70 struct {
kamg@14385 71 u2 name_index;
kamg@14385 72 u2 type_index;
kamg@14385 73 } name_and_type;
kamg@14385 74 struct {
kamg@14385 75 u2 class_index;
kamg@14385 76 u2 name_and_type_index;
kamg@14385 77 } methodref;
kamg@14385 78 uintptr_t hash;
kamg@14385 79 } _u;
kamg@14385 80
kamg@14385 81 BytecodeCPEntry() : _tag(ERROR_TAG) { _u.hash = 0; }
kamg@14385 82 BytecodeCPEntry(u1 tag) : _tag(tag) { _u.hash = 0; }
kamg@14385 83
kamg@14385 84 static BytecodeCPEntry utf8(Symbol* symbol) {
kamg@14385 85 BytecodeCPEntry bcpe(UTF8);
kamg@14385 86 bcpe._u.utf8 = symbol;
kamg@14385 87 return bcpe;
kamg@14385 88 }
kamg@14385 89
kamg@14385 90 static BytecodeCPEntry klass(u2 index) {
kamg@14385 91 BytecodeCPEntry bcpe(KLASS);
kamg@14385 92 bcpe._u.klass = index;
kamg@14385 93 return bcpe;
kamg@14385 94 }
kamg@14385 95
kamg@14385 96 static BytecodeCPEntry string(u2 index) {
kamg@14385 97 BytecodeCPEntry bcpe(STRING);
kamg@14385 98 bcpe._u.string = index;
kamg@14385 99 return bcpe;
kamg@14385 100 }
kamg@14385 101
kamg@14385 102 static BytecodeCPEntry name_and_type(u2 name, u2 type) {
kamg@14385 103 BytecodeCPEntry bcpe(NAME_AND_TYPE);
kamg@14385 104 bcpe._u.name_and_type.name_index = name;
kamg@14385 105 bcpe._u.name_and_type.type_index = type;
kamg@14385 106 return bcpe;
kamg@14385 107 }
kamg@14385 108
kamg@14385 109 static BytecodeCPEntry methodref(u2 class_index, u2 nat) {
kamg@14385 110 BytecodeCPEntry bcpe(METHODREF);
kamg@14385 111 bcpe._u.methodref.class_index = class_index;
kamg@14385 112 bcpe._u.methodref.name_and_type_index = nat;
kamg@14385 113 return bcpe;
kamg@14385 114 }
kamg@14385 115
kamg@14385 116 static bool equals(BytecodeCPEntry const& e0, BytecodeCPEntry const& e1) {
kamg@14385 117 return e0._tag == e1._tag && e0._u.hash == e1._u.hash;
kamg@14385 118 }
kamg@14385 119
kamg@14385 120 static unsigned hash(BytecodeCPEntry const& e0) {
kamg@14385 121 return (unsigned)(e0._tag ^ e0._u.hash);
kamg@14385 122 }
kamg@14385 123 };
kamg@14385 124
kamg@14385 125 class BytecodeConstantPool : ResourceObj {
kamg@14385 126 private:
kamg@14385 127 typedef ResourceHashtable<BytecodeCPEntry, u2,
kamg@14385 128 &BytecodeCPEntry::hash, &BytecodeCPEntry::equals> IndexHash;
kamg@14385 129
kamg@14385 130 ConstantPool* _orig;
kamg@14385 131 GrowableArray<BytecodeCPEntry> _entries;
kamg@14385 132 IndexHash _indices;
kamg@14385 133
kamg@14385 134 u2 find_or_add(BytecodeCPEntry const& bcpe);
kamg@14385 135
kamg@14385 136 public:
kamg@14385 137
kamg@14385 138 BytecodeConstantPool(ConstantPool* orig) : _orig(orig) {}
kamg@14385 139
kamg@14385 140 BytecodeCPEntry const& at(u2 index) const { return _entries.at(index); }
kamg@14385 141
kamg@14385 142 InstanceKlass* pool_holder() const {
coleenp@33602 143 return _orig->pool_holder();
kamg@14385 144 }
kamg@14385 145
kamg@14385 146 u2 utf8(Symbol* sym) {
kamg@14385 147 return find_or_add(BytecodeCPEntry::utf8(sym));
kamg@14385 148 }
kamg@14385 149
kamg@14385 150 u2 klass(Symbol* class_name) {
kamg@14385 151 return find_or_add(BytecodeCPEntry::klass(utf8(class_name)));
kamg@14385 152 }
kamg@14385 153
kamg@14385 154 u2 string(Symbol* str) {
kamg@14385 155 return find_or_add(BytecodeCPEntry::string(utf8(str)));
kamg@14385 156 }
kamg@14385 157
kamg@14385 158 u2 name_and_type(Symbol* name, Symbol* sig) {
kamg@14385 159 return find_or_add(BytecodeCPEntry::name_and_type(utf8(name), utf8(sig)));
kamg@14385 160 }
kamg@14385 161
kamg@14385 162 u2 methodref(Symbol* class_name, Symbol* name, Symbol* sig) {
kamg@14385 163 return find_or_add(BytecodeCPEntry::methodref(
kamg@14385 164 klass(class_name), name_and_type(name, sig)));
kamg@14385 165 }
kamg@14385 166
kamg@14385 167 ConstantPool* create_constant_pool(TRAPS) const;
kamg@14385 168 };
kamg@14385 169
kamg@14385 170 // Partial bytecode assembler - only what we need for creating
kamg@14385 171 // overpass methods for default methods is implemented
kamg@14385 172 class BytecodeAssembler : StackObj {
kamg@14385 173 private:
kamg@14385 174 BytecodeBuffer* _code;
kamg@14385 175 BytecodeConstantPool* _cp;
kamg@14385 176
kamg@14385 177 void append(u1 imm_u1);
kamg@14385 178 void append(u2 imm_u2);
kamg@14385 179 void append(u4 imm_u4);
kamg@14385 180
kamg@14385 181 void xload(u4 index, u1 quick, u1 twobyte);
kamg@14385 182
kamg@14385 183 public:
kamg@14385 184 BytecodeAssembler(BytecodeBuffer* buffer, BytecodeConstantPool* cp)
kamg@14385 185 : _code(buffer), _cp(cp) {}
kamg@14385 186
kamg@14385 187 void aload(u4 index);
kamg@14385 188 void areturn();
kamg@14385 189 void athrow();
kamg@14385 190 void checkcast(Symbol* sym);
kamg@14385 191 void dload(u4 index);
kamg@14385 192 void dreturn();
kamg@14385 193 void dup();
kamg@14385 194 void fload(u4 index);
kamg@14385 195 void freturn();
kamg@14385 196 void iload(u4 index);
kamg@14385 197 void invokespecial(Method* method);
kamg@14385 198 void invokespecial(Symbol* cls, Symbol* name, Symbol* sig);
kamg@14385 199 void invokevirtual(Method* method);
kamg@14385 200 void invokevirtual(Symbol* cls, Symbol* name, Symbol* sig);
kamg@14385 201 void ireturn();
kamg@14385 202 void ldc(u1 index);
kamg@14385 203 void ldc_w(u2 index);
kamg@14385 204 void lload(u4 index);
kamg@14385 205 void lreturn();
kamg@14385 206 void _new(Symbol* sym);
kamg@14385 207 void _return();
kamg@14385 208
kamg@14385 209 void load_string(Symbol* sym);
kamg@14385 210 void load(BasicType bt, u4 index);
kamg@14385 211 void _return(BasicType bt);
kamg@14385 212 };
kamg@14385 213
coleenp@53244 214 #endif // SHARE_CLASSFILE_BYTECODEASSEMBLER_HPP