Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/java/BinaryCode.java
38918 views
/*1* Copyright (c) 1995, 2003, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526package sun.tools.java;2728import java.io.*;2930/**31* WARNING: The contents of this source file are not part of any32* supported API. Code that depends on them does so at its own risk:33* they are subject to change or removal without notice.34*/35public class BinaryCode implements Constants {36int maxStack; // maximum stack used by code37int maxLocals; // maximum locals used by code38BinaryExceptionHandler exceptionHandlers[];39BinaryAttribute atts; // code attributes40BinaryConstantPool cpool; // constant pool of the class41byte code[]; // the byte code4243/**44* Construct the binary code from the code attribute45*/4647public48BinaryCode(byte data[], BinaryConstantPool cpool, Environment env) {49DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));50try {51this.cpool = cpool;52// JVM 4.7.4 CodeAttribute.max_stack53this.maxStack = in.readUnsignedShort();54// JVM 4.7.4 CodeAttribute.max_locals55this.maxLocals = in.readUnsignedShort();56// JVM 4.7.4 CodeAttribute.code_length57int code_length = in.readInt();58this.code = new byte[code_length];59// JVM 4.7.4 CodeAttribute.code[]60in.read(this.code);61// JVM 4.7.4 CodeAttribute.exception_table_length62int exception_count = in.readUnsignedShort();63this.exceptionHandlers = new BinaryExceptionHandler[exception_count];64for (int i = 0; i < exception_count; i++) {65// JVM 4.7.4 CodeAttribute.exception_table.start_pc66int start = in.readUnsignedShort();67// JVM 4.7.4 CodeAttribute.exception_table.end_pc68int end = in.readUnsignedShort();69// JVM 4.7.4 CodeAttribute.exception_table.handler_pc70int handler = in.readUnsignedShort();71// JVM 4.7.4 CodeAttribute.exception_table.catch_type72ClassDeclaration xclass = cpool.getDeclaration(env, in.readUnsignedShort());73this.exceptionHandlers[i] =74new BinaryExceptionHandler(start, end, handler, xclass);75}76this.atts = BinaryAttribute.load(in, cpool, ~0);77if (in.available() != 0) {78System.err.println("Should have exhausted input stream!");79}80} catch (IOException e) {81throw new CompilerError(e);82}83}848586/**87* Accessors88*/8990public BinaryExceptionHandler getExceptionHandlers()[] {91return exceptionHandlers;92}9394public byte getCode()[] { return code; }9596public int getMaxStack() { return maxStack; }9798public int getMaxLocals() { return maxLocals; }99100public BinaryAttribute getAttributes() { return atts; }101102/**103* Load a binary class104*/105public static106BinaryCode load(BinaryMember bf, BinaryConstantPool cpool, Environment env) {107byte code[] = bf.getAttribute(idCode);108return (code != null) ? new BinaryCode(code, cpool, env) : null;109}110}111112113