src/share/vm/classfile/bytecodeAssembler.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 1
2d8a650513c2
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 /*
    26  * This file has been modified by Loongson Technology in 2015. These
    27  * modifications are Copyright (c) 2015 Loongson Technology, and are made
    28  * available on the same license terms set forth above.
    29  */
    31 #include "precompiled.hpp"
    33 #include "classfile/bytecodeAssembler.hpp"
    34 #include "interpreter/bytecodes.hpp"
    35 #include "memory/oopFactory.hpp"
    36 #include "oops/constantPool.hpp"
    38 #ifdef TARGET_ARCH_x86
    39 # include "bytes_x86.hpp"
    40 #endif
    41 #ifdef TARGET_ARCH_mips
    42 # include "bytes_mips.hpp"
    43 #endif
    44 #ifdef TARGET_ARCH_sparc
    45 # include "bytes_sparc.hpp"
    46 #endif
    47 #ifdef TARGET_ARCH_zero
    48 # include "bytes_zero.hpp"
    49 #endif
    50 #ifdef TARGET_ARCH_arm
    51 # include "bytes_arm.hpp"
    52 #endif
    53 #ifdef TARGET_ARCH_ppc
    54 # include "bytes_ppc.hpp"
    55 #endif
    57 u2 BytecodeConstantPool::find_or_add(BytecodeCPEntry const& bcpe) {
    58   u2 index;
    59   u2* probe = _indices.get(bcpe);
    60   if (probe == NULL) {
    61     index = _entries.length();
    62     _entries.append(bcpe);
    63     _indices.put(bcpe, index);
    64   } else {
    65     index = *probe;
    66   }
    67   return index + _orig->length();
    68 }
    70 ConstantPool* BytecodeConstantPool::create_constant_pool(TRAPS) const {
    71   if (_entries.length() == 0) {
    72     return _orig;
    73   }
    75   ConstantPool* cp = ConstantPool::allocate(
    76       _orig->pool_holder()->class_loader_data(),
    77       _orig->length() + _entries.length(), CHECK_NULL);
    79   cp->set_pool_holder(_orig->pool_holder());
    80   _orig->copy_cp_to(1, _orig->length() - 1, cp, 1, CHECK_NULL);
    82   for (int i = 0; i < _entries.length(); ++i) {
    83     BytecodeCPEntry entry = _entries.at(i);
    84     int idx = i + _orig->length();
    85     switch (entry._tag) {
    86       case BytecodeCPEntry::UTF8:
    87         entry._u.utf8->increment_refcount();
    88         cp->symbol_at_put(idx, entry._u.utf8);
    89         break;
    90       case BytecodeCPEntry::KLASS:
    91         cp->unresolved_klass_at_put(
    92             idx, cp->symbol_at(entry._u.klass));
    93         break;
    94       case BytecodeCPEntry::STRING:
    95         cp->unresolved_string_at_put(
    96             idx, cp->symbol_at(entry._u.string));
    97         break;
    98       case BytecodeCPEntry::NAME_AND_TYPE:
    99         cp->name_and_type_at_put(idx,
   100             entry._u.name_and_type.name_index,
   101             entry._u.name_and_type.type_index);
   102         break;
   103       case BytecodeCPEntry::METHODREF:
   104         cp->method_at_put(idx,
   105             entry._u.methodref.class_index,
   106             entry._u.methodref.name_and_type_index);
   107         break;
   108       default:
   109         ShouldNotReachHere();
   110     }
   111   }
   112   return cp;
   113 }
   115 void BytecodeAssembler::append(u1 imm_u1) {
   116   _code->append(imm_u1);
   117 }
   119 void BytecodeAssembler::append(u2 imm_u2) {
   120   _code->append(0);
   121   _code->append(0);
   122   Bytes::put_Java_u2(_code->adr_at(_code->length() - 2), imm_u2);
   123 }
   125 void BytecodeAssembler::append(u4 imm_u4) {
   126   _code->append(0);
   127   _code->append(0);
   128   _code->append(0);
   129   _code->append(0);
   130   Bytes::put_Java_u4(_code->adr_at(_code->length() - 4), imm_u4);
   131 }
   133 void BytecodeAssembler::xload(u4 index, u1 onebyteop, u1 twobyteop) {
   134   if (index < 4) {
   135     _code->append(onebyteop + index);
   136   } else {
   137     _code->append(twobyteop);
   138     _code->append((u2)index);
   139   }
   140 }
   142 void BytecodeAssembler::dup() {
   143   _code->append(Bytecodes::_dup);
   144 }
   146 void BytecodeAssembler::_new(Symbol* sym) {
   147   u2 cpool_index = _cp->klass(sym);
   148   _code->append(Bytecodes::_new);
   149   append(cpool_index);
   150 }
   152 void BytecodeAssembler::load_string(Symbol* sym) {
   153   u2 cpool_index = _cp->string(sym);
   154   if (cpool_index < 0x100) {
   155     ldc(cpool_index);
   156   } else {
   157     ldc_w(cpool_index);
   158   }
   159 }
   161 void BytecodeAssembler::ldc(u1 index) {
   162   _code->append(Bytecodes::_ldc);
   163   append(index);
   164 }
   166 void BytecodeAssembler::ldc_w(u2 index) {
   167   _code->append(Bytecodes::_ldc_w);
   168   append(index);
   169 }
   171 void BytecodeAssembler::athrow() {
   172   _code->append(Bytecodes::_athrow);
   173 }
   175 void BytecodeAssembler::iload(u4 index) {
   176   xload(index, Bytecodes::_iload_0, Bytecodes::_iload);
   177 }
   179 void BytecodeAssembler::lload(u4 index) {
   180   xload(index, Bytecodes::_lload_0, Bytecodes::_lload);
   181 }
   183 void BytecodeAssembler::fload(u4 index) {
   184   xload(index, Bytecodes::_fload_0, Bytecodes::_fload);
   185 }
   187 void BytecodeAssembler::dload(u4 index) {
   188   xload(index, Bytecodes::_dload_0, Bytecodes::_dload);
   189 }
   191 void BytecodeAssembler::aload(u4 index) {
   192   xload(index, Bytecodes::_aload_0, Bytecodes::_aload);
   193 }
   195 void BytecodeAssembler::load(BasicType bt, u4 index) {
   196   switch (bt) {
   197     case T_BOOLEAN:
   198     case T_CHAR:
   199     case T_BYTE:
   200     case T_SHORT:
   201     case T_INT:     iload(index); break;
   202     case T_FLOAT:   fload(index); break;
   203     case T_DOUBLE:  dload(index); break;
   204     case T_LONG:    lload(index); break;
   205     case T_OBJECT:
   206     case T_ARRAY:   aload(index); break;
   207     default:
   208       ShouldNotReachHere();
   209   }
   210 }
   212 void BytecodeAssembler::checkcast(Symbol* sym) {
   213   u2 cpool_index = _cp->klass(sym);
   214   _code->append(Bytecodes::_checkcast);
   215   append(cpool_index);
   216 }
   218 void BytecodeAssembler::invokespecial(Method* method) {
   219   invokespecial(method->klass_name(), method->name(), method->signature());
   220 }
   222 void BytecodeAssembler::invokespecial(Symbol* klss, Symbol* name, Symbol* sig) {
   223   u2 methodref_index = _cp->methodref(klss, name, sig);
   224   _code->append(Bytecodes::_invokespecial);
   225   append(methodref_index);
   226 }
   228 void BytecodeAssembler::invokevirtual(Method* method) {
   229   invokevirtual(method->klass_name(), method->name(), method->signature());
   230 }
   232 void BytecodeAssembler::invokevirtual(Symbol* klss, Symbol* name, Symbol* sig) {
   233   u2 methodref_index = _cp->methodref(klss, name, sig);
   234   _code->append(Bytecodes::_invokevirtual);
   235   append(methodref_index);
   236 }
   238 void BytecodeAssembler::ireturn() {
   239   _code->append(Bytecodes::_ireturn);
   240 }
   242 void BytecodeAssembler::lreturn() {
   243   _code->append(Bytecodes::_lreturn);
   244 }
   246 void BytecodeAssembler::freturn() {
   247   _code->append(Bytecodes::_freturn);
   248 }
   250 void BytecodeAssembler::dreturn() {
   251   _code->append(Bytecodes::_dreturn);
   252 }
   254 void BytecodeAssembler::areturn() {
   255   _code->append(Bytecodes::_areturn);
   256 }
   258 void BytecodeAssembler::_return() {
   259   _code->append(Bytecodes::_return);
   260 }
   262 void BytecodeAssembler::_return(BasicType bt) {
   263   switch (bt) {
   264     case T_BOOLEAN:
   265     case T_CHAR:
   266     case T_BYTE:
   267     case T_SHORT:
   268     case T_INT:     ireturn(); break;
   269     case T_FLOAT:   freturn(); break;
   270     case T_DOUBLE:  dreturn(); break;
   271     case T_LONG:    lreturn(); break;
   272     case T_OBJECT:
   273     case T_ARRAY:   areturn(); break;
   274     case T_VOID:    _return(); break;
   275     default:
   276       ShouldNotReachHere();
   277   }
   278 }

mercurial