Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/bytecodeAssembler.cpp
32285 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"2526#include "classfile/bytecodeAssembler.hpp"27#include "interpreter/bytecodes.hpp"28#include "memory/oopFactory.hpp"29#include "oops/constantPool.hpp"3031#ifdef TARGET_ARCH_x8632# include "bytes_x86.hpp"33#endif34#ifdef TARGET_ARCH_sparc35# include "bytes_sparc.hpp"36#endif37#ifdef TARGET_ARCH_zero38# include "bytes_zero.hpp"39#endif40#ifdef TARGET_ARCH_arm41# include "bytes_arm.hpp"42#endif43#ifdef TARGET_ARCH_ppc44# include "bytes_ppc.hpp"45#endif46#ifdef TARGET_ARCH_aarch3247# include "bytes_aarch32.hpp"48#endif49#ifdef TARGET_ARCH_aarch6450# include "bytes_aarch64.hpp"51#endif5253u2 BytecodeConstantPool::find_or_add(BytecodeCPEntry const& bcpe) {54u2 index;55u2* probe = _indices.get(bcpe);56if (probe == NULL) {57index = _entries.length();58_entries.append(bcpe);59_indices.put(bcpe, index);60} else {61index = *probe;62}63return index + _orig->length();64}6566ConstantPool* BytecodeConstantPool::create_constant_pool(TRAPS) const {67if (_entries.length() == 0) {68return _orig;69}7071ConstantPool* cp = ConstantPool::allocate(72_orig->pool_holder()->class_loader_data(),73_orig->length() + _entries.length(), CHECK_NULL);7475cp->set_pool_holder(_orig->pool_holder());76_orig->copy_cp_to(1, _orig->length() - 1, cp, 1, CHECK_NULL);7778for (int i = 0; i < _entries.length(); ++i) {79BytecodeCPEntry entry = _entries.at(i);80int idx = i + _orig->length();81switch (entry._tag) {82case BytecodeCPEntry::UTF8:83entry._u.utf8->increment_refcount();84cp->symbol_at_put(idx, entry._u.utf8);85break;86case BytecodeCPEntry::KLASS:87cp->unresolved_klass_at_put(88idx, cp->symbol_at(entry._u.klass));89break;90case BytecodeCPEntry::STRING:91cp->unresolved_string_at_put(92idx, cp->symbol_at(entry._u.string));93break;94case BytecodeCPEntry::NAME_AND_TYPE:95cp->name_and_type_at_put(idx,96entry._u.name_and_type.name_index,97entry._u.name_and_type.type_index);98break;99case BytecodeCPEntry::METHODREF:100cp->method_at_put(idx,101entry._u.methodref.class_index,102entry._u.methodref.name_and_type_index);103break;104default:105ShouldNotReachHere();106}107}108return cp;109}110111void BytecodeAssembler::append(u1 imm_u1) {112_code->append(imm_u1);113}114115void BytecodeAssembler::append(u2 imm_u2) {116_code->append(0);117_code->append(0);118Bytes::put_Java_u2(_code->adr_at(_code->length() - 2), imm_u2);119}120121void BytecodeAssembler::append(u4 imm_u4) {122_code->append(0);123_code->append(0);124_code->append(0);125_code->append(0);126Bytes::put_Java_u4(_code->adr_at(_code->length() - 4), imm_u4);127}128129void BytecodeAssembler::xload(u4 index, u1 onebyteop, u1 twobyteop) {130if (index < 4) {131_code->append(onebyteop + index);132} else {133_code->append(twobyteop);134_code->append((u2)index);135}136}137138void BytecodeAssembler::dup() {139_code->append(Bytecodes::_dup);140}141142void BytecodeAssembler::_new(Symbol* sym) {143u2 cpool_index = _cp->klass(sym);144_code->append(Bytecodes::_new);145append(cpool_index);146}147148void BytecodeAssembler::load_string(Symbol* sym) {149u2 cpool_index = _cp->string(sym);150if (cpool_index < 0x100) {151ldc(cpool_index);152} else {153ldc_w(cpool_index);154}155}156157void BytecodeAssembler::ldc(u1 index) {158_code->append(Bytecodes::_ldc);159append(index);160}161162void BytecodeAssembler::ldc_w(u2 index) {163_code->append(Bytecodes::_ldc_w);164append(index);165}166167void BytecodeAssembler::athrow() {168_code->append(Bytecodes::_athrow);169}170171void BytecodeAssembler::iload(u4 index) {172xload(index, Bytecodes::_iload_0, Bytecodes::_iload);173}174175void BytecodeAssembler::lload(u4 index) {176xload(index, Bytecodes::_lload_0, Bytecodes::_lload);177}178179void BytecodeAssembler::fload(u4 index) {180xload(index, Bytecodes::_fload_0, Bytecodes::_fload);181}182183void BytecodeAssembler::dload(u4 index) {184xload(index, Bytecodes::_dload_0, Bytecodes::_dload);185}186187void BytecodeAssembler::aload(u4 index) {188xload(index, Bytecodes::_aload_0, Bytecodes::_aload);189}190191void BytecodeAssembler::load(BasicType bt, u4 index) {192switch (bt) {193case T_BOOLEAN:194case T_CHAR:195case T_BYTE:196case T_SHORT:197case T_INT: iload(index); break;198case T_FLOAT: fload(index); break;199case T_DOUBLE: dload(index); break;200case T_LONG: lload(index); break;201case T_OBJECT:202case T_ARRAY: aload(index); break;203default:204ShouldNotReachHere();205}206}207208void BytecodeAssembler::checkcast(Symbol* sym) {209u2 cpool_index = _cp->klass(sym);210_code->append(Bytecodes::_checkcast);211append(cpool_index);212}213214void BytecodeAssembler::invokespecial(Method* method) {215invokespecial(method->klass_name(), method->name(), method->signature());216}217218void BytecodeAssembler::invokespecial(Symbol* klss, Symbol* name, Symbol* sig) {219u2 methodref_index = _cp->methodref(klss, name, sig);220_code->append(Bytecodes::_invokespecial);221append(methodref_index);222}223224void BytecodeAssembler::invokevirtual(Method* method) {225invokevirtual(method->klass_name(), method->name(), method->signature());226}227228void BytecodeAssembler::invokevirtual(Symbol* klss, Symbol* name, Symbol* sig) {229u2 methodref_index = _cp->methodref(klss, name, sig);230_code->append(Bytecodes::_invokevirtual);231append(methodref_index);232}233234void BytecodeAssembler::ireturn() {235_code->append(Bytecodes::_ireturn);236}237238void BytecodeAssembler::lreturn() {239_code->append(Bytecodes::_lreturn);240}241242void BytecodeAssembler::freturn() {243_code->append(Bytecodes::_freturn);244}245246void BytecodeAssembler::dreturn() {247_code->append(Bytecodes::_dreturn);248}249250void BytecodeAssembler::areturn() {251_code->append(Bytecodes::_areturn);252}253254void BytecodeAssembler::_return() {255_code->append(Bytecodes::_return);256}257258void BytecodeAssembler::_return(BasicType bt) {259switch (bt) {260case T_BOOLEAN:261case T_CHAR:262case T_BYTE:263case T_SHORT:264case T_INT: ireturn(); break;265case T_FLOAT: freturn(); break;266case T_DOUBLE: dreturn(); break;267case T_LONG: lreturn(); break;268case T_OBJECT:269case T_ARRAY: areturn(); break;270case T_VOID: _return(); break;271default:272ShouldNotReachHere();273}274}275276277