feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
44
jdkSrc/jdk8/sun/tools/asm/ArrayData.java
Normal file
44
jdkSrc/jdk8/sun/tools/asm/ArrayData.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
|
||||
/**
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public final
|
||||
class ArrayData {
|
||||
Type type;
|
||||
int nargs;
|
||||
|
||||
public ArrayData(Type type, int nargs) {
|
||||
this.type = type;
|
||||
this.nargs = nargs;
|
||||
}
|
||||
}
|
||||
963
jdkSrc/jdk8/sun/tools/asm/Assembler.java
Normal file
963
jdkSrc/jdk8/sun/tools/asm/Assembler.java
Normal file
@@ -0,0 +1,963 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.util.Enumeration;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Vector;
|
||||
// JCOV
|
||||
import sun.tools.javac.*;
|
||||
import java.io.File;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.String;
|
||||
// end JCOV
|
||||
|
||||
/**
|
||||
* This class is used to assemble the bytecode instructions for a method.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*
|
||||
* @author Arthur van Hoff
|
||||
*/
|
||||
public final
|
||||
class Assembler implements Constants {
|
||||
static final int NOTREACHED = 0;
|
||||
static final int REACHED = 1;
|
||||
static final int NEEDED = 2;
|
||||
|
||||
Label first = new Label();
|
||||
Instruction last = first;
|
||||
int maxdepth;
|
||||
int maxvar;
|
||||
int maxpc;
|
||||
|
||||
/**
|
||||
* Add an instruction
|
||||
*/
|
||||
public void add(Instruction inst) {
|
||||
if (inst != null) {
|
||||
last.next = inst;
|
||||
last = inst;
|
||||
}
|
||||
}
|
||||
public void add(long where, int opc) {
|
||||
add(new Instruction(where, opc, null));
|
||||
}
|
||||
public void add(long where, int opc, Object obj) {
|
||||
add(new Instruction(where, opc, obj));
|
||||
}
|
||||
// JCOV
|
||||
public void add(long where, int opc, Object obj, boolean flagCondInverted) {
|
||||
add(new Instruction(where, opc, obj, flagCondInverted));
|
||||
}
|
||||
|
||||
public void add(boolean flagNoCovered, long where, int opc, Object obj) {
|
||||
add(new Instruction(flagNoCovered, where, opc, obj));
|
||||
}
|
||||
|
||||
public void add(long where, int opc, boolean flagNoCovered) {
|
||||
add(new Instruction(where, opc, flagNoCovered));
|
||||
}
|
||||
|
||||
static Vector<String> SourceClassList = new Vector<>();
|
||||
|
||||
static Vector<String> TmpCovTable = new Vector<>();
|
||||
|
||||
static int[] JcovClassCountArray = new int[CT_LAST_KIND + 1];
|
||||
|
||||
static String JcovMagicLine = "JCOV-DATA-FILE-VERSION: 2.0";
|
||||
static String JcovClassLine = "CLASS: ";
|
||||
static String JcovSrcfileLine = "SRCFILE: ";
|
||||
static String JcovTimestampLine = "TIMESTAMP: ";
|
||||
static String JcovDataLine = "DATA: ";
|
||||
static String JcovHeadingLine = "#kind\tcount";
|
||||
|
||||
static int[] arrayModifiers =
|
||||
{M_PUBLIC, M_PRIVATE, M_PROTECTED, M_ABSTRACT, M_FINAL, M_INTERFACE};
|
||||
static int[] arrayModifiersOpc =
|
||||
{PUBLIC, PRIVATE, PROTECTED, ABSTRACT, FINAL, INTERFACE};
|
||||
//end JCOV
|
||||
|
||||
/**
|
||||
* Optimize instructions and mark those that can be reached
|
||||
*/
|
||||
void optimize(Environment env, Label lbl) {
|
||||
lbl.pc = REACHED;
|
||||
|
||||
for (Instruction inst = lbl.next ; inst != null ; inst = inst.next) {
|
||||
switch (inst.pc) {
|
||||
case NOTREACHED:
|
||||
inst.optimize(env);
|
||||
inst.pc = REACHED;
|
||||
break;
|
||||
case REACHED:
|
||||
return;
|
||||
case NEEDED:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (inst.opc) {
|
||||
case opc_label:
|
||||
case opc_dead:
|
||||
if (inst.pc == REACHED) {
|
||||
inst.pc = NOTREACHED;
|
||||
}
|
||||
break;
|
||||
|
||||
case opc_ifeq:
|
||||
case opc_ifne:
|
||||
case opc_ifgt:
|
||||
case opc_ifge:
|
||||
case opc_iflt:
|
||||
case opc_ifle:
|
||||
case opc_if_icmpeq:
|
||||
case opc_if_icmpne:
|
||||
case opc_if_icmpgt:
|
||||
case opc_if_icmpge:
|
||||
case opc_if_icmplt:
|
||||
case opc_if_icmple:
|
||||
case opc_if_acmpeq:
|
||||
case opc_if_acmpne:
|
||||
case opc_ifnull:
|
||||
case opc_ifnonnull:
|
||||
optimize(env, (Label)inst.value);
|
||||
break;
|
||||
|
||||
case opc_goto:
|
||||
optimize(env, (Label)inst.value);
|
||||
return;
|
||||
|
||||
case opc_jsr:
|
||||
optimize(env, (Label)inst.value);
|
||||
break;
|
||||
|
||||
case opc_ret:
|
||||
case opc_return:
|
||||
case opc_ireturn:
|
||||
case opc_lreturn:
|
||||
case opc_freturn:
|
||||
case opc_dreturn:
|
||||
case opc_areturn:
|
||||
case opc_athrow:
|
||||
return;
|
||||
|
||||
case opc_tableswitch:
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)inst.value;
|
||||
optimize(env, sw.defaultLabel);
|
||||
for (Enumeration<Label> e = sw.tab.elements() ; e.hasMoreElements();) {
|
||||
optimize(env, e.nextElement());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case opc_try: {
|
||||
TryData td = (TryData)inst.value;
|
||||
td.getEndLabel().pc = NEEDED;
|
||||
for (Enumeration<CatchData> e = td.catches.elements() ; e.hasMoreElements();) {
|
||||
CatchData cd = e.nextElement();
|
||||
optimize(env, cd.getLabel());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Eliminate instructions that are not reached
|
||||
*/
|
||||
boolean eliminate() {
|
||||
boolean change = false;
|
||||
Instruction prev = first;
|
||||
|
||||
for (Instruction inst = first.next ; inst != null ; inst = inst.next) {
|
||||
if (inst.pc != NOTREACHED) {
|
||||
prev.next = inst;
|
||||
prev = inst;
|
||||
inst.pc = NOTREACHED;
|
||||
} else {
|
||||
change = true;
|
||||
}
|
||||
}
|
||||
first.pc = NOTREACHED;
|
||||
prev.next = null;
|
||||
return change;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize the byte codes
|
||||
*/
|
||||
public void optimize(Environment env) {
|
||||
//listing(System.out);
|
||||
do {
|
||||
// Figure out which instructions are reached
|
||||
optimize(env, first);
|
||||
|
||||
// Eliminate instructions that are not reached
|
||||
} while (eliminate() && env.opt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all constants into the constant table
|
||||
*/
|
||||
public void collect(Environment env, MemberDefinition field, ConstantPool tab) {
|
||||
// Collect constants for arguments only
|
||||
// if a local variable table is generated
|
||||
if ((field != null) && env.debug_vars()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Vector<MemberDefinition> v = (Vector<MemberDefinition>)field.getArguments();
|
||||
if (v != null) {
|
||||
for (Enumeration<MemberDefinition> e = v.elements() ; e.hasMoreElements() ;) {
|
||||
MemberDefinition f = e.nextElement();
|
||||
tab.put(f.getName().toString());
|
||||
tab.put(f.getType().getTypeSignature());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect constants from the instructions
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
inst.collect(tab);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine stack size, count local variables
|
||||
*/
|
||||
void balance(Label lbl, int depth) {
|
||||
for (Instruction inst = lbl ; inst != null ; inst = inst.next) {
|
||||
//Environment.debugOutput(inst.toString() + ": " + depth + " => " +
|
||||
// (depth + inst.balance()));
|
||||
depth += inst.balance();
|
||||
if (depth < 0) {
|
||||
throw new CompilerError("stack under flow: " + inst.toString() + " = " + depth);
|
||||
}
|
||||
if (depth > maxdepth) {
|
||||
maxdepth = depth;
|
||||
}
|
||||
switch (inst.opc) {
|
||||
case opc_label:
|
||||
lbl = (Label)inst;
|
||||
if (inst.pc == REACHED) {
|
||||
if (lbl.depth != depth) {
|
||||
throw new CompilerError("stack depth error " +
|
||||
depth + "/" + lbl.depth +
|
||||
": " + inst.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
lbl.pc = REACHED;
|
||||
lbl.depth = depth;
|
||||
break;
|
||||
|
||||
case opc_ifeq:
|
||||
case opc_ifne:
|
||||
case opc_ifgt:
|
||||
case opc_ifge:
|
||||
case opc_iflt:
|
||||
case opc_ifle:
|
||||
case opc_if_icmpeq:
|
||||
case opc_if_icmpne:
|
||||
case opc_if_icmpgt:
|
||||
case opc_if_icmpge:
|
||||
case opc_if_icmplt:
|
||||
case opc_if_icmple:
|
||||
case opc_if_acmpeq:
|
||||
case opc_if_acmpne:
|
||||
case opc_ifnull:
|
||||
case opc_ifnonnull:
|
||||
balance((Label)inst.value, depth);
|
||||
break;
|
||||
|
||||
case opc_goto:
|
||||
balance((Label)inst.value, depth);
|
||||
return;
|
||||
|
||||
case opc_jsr:
|
||||
balance((Label)inst.value, depth + 1);
|
||||
break;
|
||||
|
||||
case opc_ret:
|
||||
case opc_return:
|
||||
case opc_ireturn:
|
||||
case opc_lreturn:
|
||||
case opc_freturn:
|
||||
case opc_dreturn:
|
||||
case opc_areturn:
|
||||
case opc_athrow:
|
||||
return;
|
||||
|
||||
case opc_iload:
|
||||
case opc_fload:
|
||||
case opc_aload:
|
||||
case opc_istore:
|
||||
case opc_fstore:
|
||||
case opc_astore: {
|
||||
int v = ((inst.value instanceof Number)
|
||||
? ((Number)inst.value).intValue()
|
||||
: ((LocalVariable)inst.value).slot) + 1;
|
||||
if (v > maxvar)
|
||||
maxvar = v;
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_lload:
|
||||
case opc_dload:
|
||||
case opc_lstore:
|
||||
case opc_dstore: {
|
||||
int v = ((inst.value instanceof Number)
|
||||
? ((Number)inst.value).intValue()
|
||||
: ((LocalVariable)inst.value).slot) + 2;
|
||||
if (v > maxvar)
|
||||
maxvar = v;
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_iinc: {
|
||||
int v = ((int[])inst.value)[0] + 1;
|
||||
if (v > maxvar)
|
||||
maxvar = v + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_tableswitch:
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)inst.value;
|
||||
balance(sw.defaultLabel, depth);
|
||||
for (Enumeration<Label> e = sw.tab.elements() ; e.hasMoreElements();) {
|
||||
balance(e.nextElement(), depth);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case opc_try: {
|
||||
TryData td = (TryData)inst.value;
|
||||
for (Enumeration<CatchData> e = td.catches.elements() ; e.hasMoreElements();) {
|
||||
CatchData cd = e.nextElement();
|
||||
balance(cd.getLabel(), depth + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate code
|
||||
*/
|
||||
public void write(Environment env, DataOutputStream out,
|
||||
MemberDefinition field, ConstantPool tab)
|
||||
throws IOException {
|
||||
//listing(System.out);
|
||||
|
||||
if ((field != null) && field.getArguments() != null) {
|
||||
int sum = 0;
|
||||
@SuppressWarnings("unchecked")
|
||||
Vector<MemberDefinition> v = (Vector<MemberDefinition>)field.getArguments();
|
||||
for (Enumeration<MemberDefinition> e = v.elements(); e.hasMoreElements(); ) {
|
||||
MemberDefinition f = e.nextElement();
|
||||
sum += f.getType().stackSize();
|
||||
}
|
||||
maxvar = sum;
|
||||
}
|
||||
|
||||
// Make sure the stack balances. Also calculate maxvar and maxstack
|
||||
try {
|
||||
balance(first, 0);
|
||||
} catch (CompilerError e) {
|
||||
System.out.println("ERROR: " + e);
|
||||
listing(System.out);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Assign PCs
|
||||
int pc = 0, nexceptions = 0;
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
inst.pc = pc;
|
||||
int sz = inst.size(tab);
|
||||
if (pc<65536 && (pc+sz)>=65536) {
|
||||
env.error(inst.where, "warn.method.too.long");
|
||||
}
|
||||
pc += sz;
|
||||
|
||||
if (inst.opc == opc_try) {
|
||||
nexceptions += ((TryData)inst.value).catches.size();
|
||||
}
|
||||
}
|
||||
|
||||
// Write header
|
||||
out.writeShort(maxdepth);
|
||||
out.writeShort(maxvar);
|
||||
out.writeInt(maxpc = pc);
|
||||
|
||||
// Generate code
|
||||
for (Instruction inst = first.next ; inst != null ; inst = inst.next) {
|
||||
inst.write(out, tab);
|
||||
}
|
||||
|
||||
// write exceptions
|
||||
out.writeShort(nexceptions);
|
||||
if (nexceptions > 0) {
|
||||
//listing(System.out);
|
||||
writeExceptions(env, out, tab, first, last);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the exceptions table
|
||||
*/
|
||||
void writeExceptions(Environment env, DataOutputStream out, ConstantPool tab, Instruction first, Instruction last) throws IOException {
|
||||
for (Instruction inst = first ; inst != last.next ; inst = inst.next) {
|
||||
if (inst.opc == opc_try) {
|
||||
TryData td = (TryData)inst.value;
|
||||
writeExceptions(env, out, tab, inst.next, td.getEndLabel());
|
||||
for (Enumeration<CatchData> e = td.catches.elements() ; e.hasMoreElements();) {
|
||||
CatchData cd = e.nextElement();
|
||||
//System.out.println("EXCEPTION: " + env.getSource() + ", pc=" + inst.pc + ", end=" + td.getEndLabel().pc + ", hdl=" + cd.getLabel().pc + ", tp=" + cd.getType());
|
||||
out.writeShort(inst.pc);
|
||||
out.writeShort(td.getEndLabel().pc);
|
||||
out.writeShort(cd.getLabel().pc);
|
||||
if (cd.getType() != null) {
|
||||
out.writeShort(tab.index(cd.getType()));
|
||||
} else {
|
||||
out.writeShort(0);
|
||||
}
|
||||
}
|
||||
inst = td.getEndLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//JCOV
|
||||
/**
|
||||
* Write the coverage table
|
||||
*/
|
||||
public void writeCoverageTable(Environment env, ClassDefinition c, DataOutputStream out, ConstantPool tab, long whereField) throws IOException {
|
||||
Vector<Cover> TableLot = new Vector<>(); /* Coverage table */
|
||||
boolean begseg = false;
|
||||
boolean begmeth = false;
|
||||
@SuppressWarnings("deprecation")
|
||||
long whereClass = ((SourceClass)c).getWhere();
|
||||
Vector<Long> whereTry = new Vector<>();
|
||||
int numberTry = 0;
|
||||
int count = 0;
|
||||
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
long n = (inst.where >> WHEREOFFSETBITS);
|
||||
if (n > 0 && inst.opc != opc_label) {
|
||||
if (!begmeth) {
|
||||
if ( whereClass == inst.where)
|
||||
TableLot.addElement(new Cover(CT_FIKT_METHOD, whereField, inst.pc));
|
||||
else
|
||||
TableLot.addElement(new Cover(CT_METHOD, whereField, inst.pc));
|
||||
count++;
|
||||
begmeth = true;
|
||||
}
|
||||
if (!begseg && !inst.flagNoCovered ) {
|
||||
boolean findTry = false;
|
||||
for (Enumeration<Long> e = whereTry.elements(); e.hasMoreElements();) {
|
||||
if (e.nextElement().longValue() == inst.where) {
|
||||
findTry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!findTry) {
|
||||
TableLot.addElement(new Cover(CT_BLOCK, inst.where, inst.pc));
|
||||
count++;
|
||||
begseg = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (inst.opc) {
|
||||
case opc_label:
|
||||
begseg = false;
|
||||
break;
|
||||
case opc_ifeq:
|
||||
case opc_ifne:
|
||||
case opc_ifnull:
|
||||
case opc_ifnonnull:
|
||||
case opc_ifgt:
|
||||
case opc_ifge:
|
||||
case opc_iflt:
|
||||
case opc_ifle:
|
||||
case opc_if_icmpeq:
|
||||
case opc_if_icmpne:
|
||||
case opc_if_icmpgt:
|
||||
case opc_if_icmpge:
|
||||
case opc_if_icmplt:
|
||||
case opc_if_icmple:
|
||||
case opc_if_acmpeq:
|
||||
case opc_if_acmpne: {
|
||||
if ( inst.flagCondInverted ) {
|
||||
TableLot.addElement(new Cover(CT_BRANCH_TRUE, inst.where, inst.pc));
|
||||
TableLot.addElement(new Cover(CT_BRANCH_FALSE, inst.where, inst.pc));
|
||||
} else {
|
||||
TableLot.addElement(new Cover(CT_BRANCH_FALSE, inst.where, inst.pc));
|
||||
TableLot.addElement(new Cover(CT_BRANCH_TRUE, inst.where, inst.pc));
|
||||
}
|
||||
count += 2;
|
||||
begseg = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_goto: {
|
||||
begseg = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_ret:
|
||||
case opc_return:
|
||||
case opc_ireturn:
|
||||
case opc_lreturn:
|
||||
case opc_freturn:
|
||||
case opc_dreturn:
|
||||
case opc_areturn:
|
||||
case opc_athrow: {
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_try: {
|
||||
whereTry.addElement(Long.valueOf(inst.where));
|
||||
begseg = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_tableswitch: {
|
||||
SwitchData sw = (SwitchData)inst.value;
|
||||
for (int i = sw.minValue; i <= sw.maxValue; i++) {
|
||||
TableLot.addElement(new Cover(CT_CASE, sw.whereCase(new Integer(i)), inst.pc));
|
||||
count++;
|
||||
}
|
||||
if (!sw.getDefault()) {
|
||||
TableLot.addElement(new Cover(CT_SWITH_WO_DEF, inst.where, inst.pc));
|
||||
count++;
|
||||
} else {
|
||||
TableLot.addElement(new Cover(CT_CASE, sw.whereCase("default"), inst.pc));
|
||||
count++;
|
||||
}
|
||||
begseg = false;
|
||||
break;
|
||||
}
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)inst.value;
|
||||
for (Enumeration<Integer> e = sw.sortedKeys(); e.hasMoreElements() ; ) {
|
||||
Integer v = e.nextElement();
|
||||
TableLot.addElement(new Cover(CT_CASE, sw.whereCase(v), inst.pc));
|
||||
count++;
|
||||
}
|
||||
if (!sw.getDefault()) {
|
||||
TableLot.addElement(new Cover(CT_SWITH_WO_DEF, inst.where, inst.pc));
|
||||
count++;
|
||||
} else {
|
||||
TableLot.addElement(new Cover(CT_CASE, sw.whereCase("default"), inst.pc));
|
||||
count++;
|
||||
}
|
||||
begseg = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Cover Lot;
|
||||
long ln, pos;
|
||||
|
||||
out.writeShort(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
Lot = TableLot.elementAt(i);
|
||||
ln = (Lot.Addr >> WHEREOFFSETBITS);
|
||||
pos = (Lot.Addr << (64 - WHEREOFFSETBITS)) >> (64 - WHEREOFFSETBITS);
|
||||
out.writeShort(Lot.NumCommand);
|
||||
out.writeShort(Lot.Type);
|
||||
out.writeInt((int)ln);
|
||||
out.writeInt((int)pos);
|
||||
|
||||
if ( !(Lot.Type == CT_CASE && Lot.Addr == 0) ) {
|
||||
JcovClassCountArray[Lot.Type]++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Increase count of methods for native methods
|
||||
*/
|
||||
|
||||
public void addNativeToJcovTab(Environment env, ClassDefinition c) {
|
||||
JcovClassCountArray[CT_METHOD]++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create class jcov element
|
||||
*/
|
||||
|
||||
private String createClassJcovElement(Environment env, ClassDefinition c) {
|
||||
String SourceClass = (Type.mangleInnerType((c.getClassDeclaration()).getName())).toString();
|
||||
String ConvSourceClass;
|
||||
String classJcovLine;
|
||||
|
||||
SourceClassList.addElement(SourceClass);
|
||||
ConvSourceClass = SourceClass.replace('.', '/');
|
||||
classJcovLine = JcovClassLine + ConvSourceClass;
|
||||
|
||||
classJcovLine = classJcovLine + " [";
|
||||
String blank = "";
|
||||
|
||||
for (int i = 0; i < arrayModifiers.length; i++ ) {
|
||||
if ((c.getModifiers() & arrayModifiers[i]) != 0) {
|
||||
classJcovLine = classJcovLine + blank + opNames[arrayModifiersOpc[i]];
|
||||
blank = " ";
|
||||
}
|
||||
}
|
||||
classJcovLine = classJcovLine + "]";
|
||||
|
||||
return classJcovLine;
|
||||
}
|
||||
|
||||
/*
|
||||
* generate coverage data
|
||||
*/
|
||||
|
||||
public void GenVecJCov(Environment env, ClassDefinition c, long Time) {
|
||||
@SuppressWarnings("deprecation")
|
||||
String SourceFile = ((SourceClass)c).getAbsoluteName();
|
||||
|
||||
TmpCovTable.addElement(createClassJcovElement(env, c));
|
||||
TmpCovTable.addElement(JcovSrcfileLine + SourceFile);
|
||||
TmpCovTable.addElement(JcovTimestampLine + Time);
|
||||
TmpCovTable.addElement(JcovDataLine + "A"); // data format
|
||||
TmpCovTable.addElement(JcovHeadingLine);
|
||||
|
||||
for (int i = CT_FIRST_KIND; i <= CT_LAST_KIND; i++) {
|
||||
if (JcovClassCountArray[i] != 0) {
|
||||
TmpCovTable.addElement(new String(i + "\t" + JcovClassCountArray[i]));
|
||||
JcovClassCountArray[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* generate file of coverage data
|
||||
*/
|
||||
|
||||
@SuppressWarnings("deprecation") // for JCovd.readLine() calls
|
||||
public void GenJCov(Environment env) {
|
||||
|
||||
try {
|
||||
File outFile = env.getcovFile();
|
||||
if( outFile.exists()) {
|
||||
DataInputStream JCovd = new DataInputStream(
|
||||
new BufferedInputStream(
|
||||
new FileInputStream(outFile)));
|
||||
String CurrLine = null;
|
||||
boolean first = true;
|
||||
String Class;
|
||||
|
||||
CurrLine = JCovd.readLine();
|
||||
if ((CurrLine != null) && CurrLine.startsWith(JcovMagicLine)) {
|
||||
// this is a good Jcov file
|
||||
|
||||
while((CurrLine = JCovd.readLine()) != null ) {
|
||||
if ( CurrLine.startsWith(JcovClassLine) ) {
|
||||
first = true;
|
||||
for(Enumeration<String> e = SourceClassList.elements(); e.hasMoreElements();) {
|
||||
String clsName = CurrLine.substring(JcovClassLine.length());
|
||||
int idx = clsName.indexOf(' ');
|
||||
|
||||
if (idx != -1) {
|
||||
clsName = clsName.substring(0, idx);
|
||||
}
|
||||
Class = e.nextElement();
|
||||
if ( Class.compareTo(clsName) == 0) {
|
||||
first = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (first) // re-write old class
|
||||
TmpCovTable.addElement(CurrLine);
|
||||
}
|
||||
}
|
||||
JCovd.close();
|
||||
}
|
||||
PrintStream CovFile = new PrintStream(new DataOutputStream(new FileOutputStream(outFile)));
|
||||
CovFile.println(JcovMagicLine);
|
||||
for(Enumeration<String> e = TmpCovTable.elements(); e.hasMoreElements();) {
|
||||
CovFile.println(e.nextElement());
|
||||
}
|
||||
CovFile.close();
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
System.out.println("ERROR: " + e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("ERROR: " + e);
|
||||
}
|
||||
}
|
||||
// end JCOV
|
||||
|
||||
|
||||
/**
|
||||
* Write the linenumber table
|
||||
*/
|
||||
public void writeLineNumberTable(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
long ln = -1;
|
||||
int count = 0;
|
||||
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
long n = (inst.where >> WHEREOFFSETBITS);
|
||||
if ((n > 0) && (ln != n)) {
|
||||
ln = n;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
ln = -1;
|
||||
out.writeShort(count);
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
long n = (inst.where >> WHEREOFFSETBITS);
|
||||
if ((n > 0) && (ln != n)) {
|
||||
ln = n;
|
||||
out.writeShort(inst.pc);
|
||||
out.writeShort((int)ln);
|
||||
//System.out.println("pc = " + inst.pc + ", ln = " + ln);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out when registers contain a legal value. This is done
|
||||
* using a simple data flow algorithm. This information is later used
|
||||
* to generate the local variable table.
|
||||
*/
|
||||
void flowFields(Environment env, Label lbl, MemberDefinition locals[]) {
|
||||
if (lbl.locals != null) {
|
||||
// Been here before. Erase any conflicts.
|
||||
MemberDefinition f[] = lbl.locals;
|
||||
for (int i = 0 ; i < maxvar ; i++) {
|
||||
if (f[i] != locals[i]) {
|
||||
f[i] = null;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Remember the set of active registers at this point
|
||||
lbl.locals = new MemberDefinition[maxvar];
|
||||
System.arraycopy(locals, 0, lbl.locals, 0, maxvar);
|
||||
|
||||
MemberDefinition newlocals[] = new MemberDefinition[maxvar];
|
||||
System.arraycopy(locals, 0, newlocals, 0, maxvar);
|
||||
locals = newlocals;
|
||||
|
||||
for (Instruction inst = lbl.next ; inst != null ; inst = inst.next) {
|
||||
switch (inst.opc) {
|
||||
case opc_istore: case opc_istore_0: case opc_istore_1:
|
||||
case opc_istore_2: case opc_istore_3:
|
||||
case opc_fstore: case opc_fstore_0: case opc_fstore_1:
|
||||
case opc_fstore_2: case opc_fstore_3:
|
||||
case opc_astore: case opc_astore_0: case opc_astore_1:
|
||||
case opc_astore_2: case opc_astore_3:
|
||||
case opc_lstore: case opc_lstore_0: case opc_lstore_1:
|
||||
case opc_lstore_2: case opc_lstore_3:
|
||||
case opc_dstore: case opc_dstore_0: case opc_dstore_1:
|
||||
case opc_dstore_2: case opc_dstore_3:
|
||||
if (inst.value instanceof LocalVariable) {
|
||||
LocalVariable v = (LocalVariable)inst.value;
|
||||
locals[v.slot] = v.field;
|
||||
}
|
||||
break;
|
||||
|
||||
case opc_label:
|
||||
flowFields(env, (Label)inst, locals);
|
||||
return;
|
||||
|
||||
case opc_ifeq: case opc_ifne: case opc_ifgt:
|
||||
case opc_ifge: case opc_iflt: case opc_ifle:
|
||||
case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpgt:
|
||||
case opc_if_icmpge: case opc_if_icmplt: case opc_if_icmple:
|
||||
case opc_if_acmpeq: case opc_if_acmpne:
|
||||
case opc_ifnull: case opc_ifnonnull:
|
||||
case opc_jsr:
|
||||
flowFields(env, (Label)inst.value, locals);
|
||||
break;
|
||||
|
||||
case opc_goto:
|
||||
flowFields(env, (Label)inst.value, locals);
|
||||
return;
|
||||
|
||||
case opc_return: case opc_ireturn: case opc_lreturn:
|
||||
case opc_freturn: case opc_dreturn: case opc_areturn:
|
||||
case opc_athrow: case opc_ret:
|
||||
return;
|
||||
|
||||
case opc_tableswitch:
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)inst.value;
|
||||
flowFields(env, sw.defaultLabel, locals);
|
||||
for (Enumeration<Label> e = sw.tab.elements() ; e.hasMoreElements();) {
|
||||
flowFields(env, e.nextElement(), locals);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case opc_try: {
|
||||
Vector<CatchData> catches = ((TryData)inst.value).catches;
|
||||
for (Enumeration<CatchData> e = catches.elements(); e.hasMoreElements();) {
|
||||
CatchData cd = e.nextElement();
|
||||
flowFields(env, cd.getLabel(), locals);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the local variable table. The necessary constants have already been
|
||||
* added to the constant table by the collect() method. The flowFields method
|
||||
* is used to determine which variables are alive at each pc.
|
||||
*/
|
||||
public void writeLocalVariableTable(Environment env, MemberDefinition field, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
MemberDefinition locals[] = new MemberDefinition[maxvar];
|
||||
int i = 0;
|
||||
|
||||
// Initialize arguments
|
||||
if ((field != null) && (field.getArguments() != null)) {
|
||||
int reg = 0;
|
||||
@SuppressWarnings("unchecked")
|
||||
Vector<MemberDefinition> v = (Vector<MemberDefinition>)field.getArguments();
|
||||
for (Enumeration<MemberDefinition> e = v.elements(); e.hasMoreElements(); ) {
|
||||
MemberDefinition f = e.nextElement();
|
||||
locals[reg] = f;
|
||||
reg += f.getType().stackSize();
|
||||
}
|
||||
}
|
||||
|
||||
flowFields(env, first, locals);
|
||||
LocalVariableTable lvtab = new LocalVariableTable();
|
||||
|
||||
// Initialize arguments again
|
||||
for (i = 0; i < maxvar; i++)
|
||||
locals[i] = null;
|
||||
if ((field != null) && (field.getArguments() != null)) {
|
||||
int reg = 0;
|
||||
@SuppressWarnings("unchecked")
|
||||
Vector<MemberDefinition> v = (Vector<MemberDefinition>)field.getArguments();
|
||||
for (Enumeration<MemberDefinition> e = v.elements(); e.hasMoreElements(); ) {
|
||||
MemberDefinition f = e.nextElement();
|
||||
locals[reg] = f;
|
||||
lvtab.define(f, reg, 0, maxpc);
|
||||
reg += f.getType().stackSize();
|
||||
}
|
||||
}
|
||||
|
||||
int pcs[] = new int[maxvar];
|
||||
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
switch (inst.opc) {
|
||||
case opc_istore: case opc_istore_0: case opc_istore_1:
|
||||
case opc_istore_2: case opc_istore_3: case opc_fstore:
|
||||
case opc_fstore_0: case opc_fstore_1: case opc_fstore_2:
|
||||
case opc_fstore_3:
|
||||
case opc_astore: case opc_astore_0: case opc_astore_1:
|
||||
case opc_astore_2: case opc_astore_3:
|
||||
case opc_lstore: case opc_lstore_0: case opc_lstore_1:
|
||||
case opc_lstore_2: case opc_lstore_3:
|
||||
case opc_dstore: case opc_dstore_0: case opc_dstore_1:
|
||||
case opc_dstore_2: case opc_dstore_3:
|
||||
if (inst.value instanceof LocalVariable) {
|
||||
LocalVariable v = (LocalVariable)inst.value;
|
||||
int pc = (inst.next != null) ? inst.next.pc : inst.pc;
|
||||
if (locals[v.slot] != null) {
|
||||
lvtab.define(locals[v.slot], v.slot, pcs[v.slot], pc);
|
||||
}
|
||||
pcs[v.slot] = pc;
|
||||
locals[v.slot] = v.field;
|
||||
}
|
||||
break;
|
||||
|
||||
case opc_label: {
|
||||
// flush previous labels
|
||||
for (i = 0 ; i < maxvar ; i++) {
|
||||
if (locals[i] != null) {
|
||||
lvtab.define(locals[i], i, pcs[i], inst.pc);
|
||||
}
|
||||
}
|
||||
// init new labels
|
||||
int pc = inst.pc;
|
||||
MemberDefinition[] labelLocals = ((Label)inst).locals;
|
||||
if (labelLocals == null) { // unreachable code??
|
||||
for (i = 0; i < maxvar; i++)
|
||||
locals[i] = null;
|
||||
} else {
|
||||
System.arraycopy(labelLocals, 0, locals, 0, maxvar);
|
||||
}
|
||||
for (i = 0 ; i < maxvar ; i++) {
|
||||
pcs[i] = pc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// flush remaining labels
|
||||
for (i = 0 ; i < maxvar ; i++) {
|
||||
if (locals[i] != null) {
|
||||
lvtab.define(locals[i], i, pcs[i], maxpc);
|
||||
}
|
||||
}
|
||||
|
||||
// write the local variable table
|
||||
lvtab.write(env, out, tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if empty
|
||||
*/
|
||||
public boolean empty() {
|
||||
return first == last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the byte codes
|
||||
*/
|
||||
public void listing(PrintStream out) {
|
||||
out.println("-- listing --");
|
||||
for (Instruction inst = first ; inst != null ; inst = inst.next) {
|
||||
out.println(inst.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
62
jdkSrc/jdk8/sun/tools/asm/CatchData.java
Normal file
62
jdkSrc/jdk8/sun/tools/asm/CatchData.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public final
|
||||
class CatchData {
|
||||
Object type;
|
||||
Label label;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
CatchData(Object type) {
|
||||
this.type = type;
|
||||
this.label = new Label();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label
|
||||
*/
|
||||
public Label getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the clazz
|
||||
*/
|
||||
public Object getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
79
jdkSrc/jdk8/sun/tools/asm/ClassConstantData.java
Normal file
79
jdkSrc/jdk8/sun/tools/asm/ClassConstantData.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* This is a class constant pool item.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class ClassConstantData extends ConstantPoolData {
|
||||
String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
ClassConstantData(ConstantPool tab, ClassDeclaration clazz) {
|
||||
String sig = clazz.getType().getTypeSignature();
|
||||
// sig is like "Lfoo/bar;", name is like "foo/bar".
|
||||
// We assume SIG_CLASS and SIG_ENDCLASS are 1 char each.
|
||||
name = sig.substring(1, sig.length()-1);
|
||||
tab.put(name);
|
||||
}
|
||||
|
||||
// REMIND: this case should eventually go away.
|
||||
ClassConstantData(ConstantPool tab, Type t) {
|
||||
name = t.getTypeSignature();
|
||||
tab.put(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
out.writeByte(CONSTANT_CLASS);
|
||||
out.writeShort(tab.index(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ClassConstantData[" + name + "]";
|
||||
}
|
||||
}
|
||||
176
jdkSrc/jdk8/sun/tools/asm/ConstantPool.java
Normal file
176
jdkSrc/jdk8/sun/tools/asm/ConstantPool.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import sun.tools.tree.StringExpression;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* A table of constants
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public final
|
||||
class ConstantPool implements RuntimeConstants {
|
||||
Hashtable<Object,ConstantPoolData> hash = new Hashtable<>(101);
|
||||
|
||||
/**
|
||||
* Find an entry, may return 0
|
||||
*/
|
||||
public int index(Object obj) {
|
||||
return hash.get(obj).index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry
|
||||
*/
|
||||
public void put(Object obj) {
|
||||
ConstantPoolData data = hash.get(obj);
|
||||
if (data == null) {
|
||||
if (obj instanceof String) {
|
||||
data = new StringConstantData(this, (String)obj);
|
||||
} else if (obj instanceof StringExpression) {
|
||||
data = new StringExpressionConstantData(this, (StringExpression)obj);
|
||||
} else if (obj instanceof ClassDeclaration) {
|
||||
data = new ClassConstantData(this, (ClassDeclaration)obj);
|
||||
} else if (obj instanceof Type) {
|
||||
data = new ClassConstantData(this, (Type)obj);
|
||||
} else if (obj instanceof MemberDefinition) {
|
||||
data = new FieldConstantData(this, (MemberDefinition)obj);
|
||||
} else if (obj instanceof NameAndTypeData) {
|
||||
data = new NameAndTypeConstantData(this, (NameAndTypeData)obj);
|
||||
} else if (obj instanceof Number) {
|
||||
data = new NumberConstantData(this, (Number)obj);
|
||||
}
|
||||
hash.put(obj, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to output
|
||||
*/
|
||||
public void write(Environment env, DataOutputStream out) throws IOException {
|
||||
ConstantPoolData list[] = new ConstantPoolData[hash.size()];
|
||||
String keys[] = new String[list.length];
|
||||
int index = 1, count = 0;
|
||||
|
||||
// Make a list of all the constant pool items
|
||||
for (int n = 0 ; n < 5 ; n++) {
|
||||
int first = count;
|
||||
for (Enumeration<ConstantPoolData> e = hash.elements() ; e.hasMoreElements() ;) {
|
||||
ConstantPoolData data = e.nextElement();
|
||||
if (data.order() == n) {
|
||||
keys[count] = sortKey(data);
|
||||
list[count++] = data;
|
||||
}
|
||||
}
|
||||
xsort(list, keys, first, count-1);
|
||||
}
|
||||
|
||||
// Assign an index to each constant pool item
|
||||
for (int n = 0 ; n < list.length ; n++) {
|
||||
ConstantPoolData data = list[n];
|
||||
data.index = index;
|
||||
index += data.width();
|
||||
}
|
||||
|
||||
// Write length
|
||||
out.writeShort(index);
|
||||
|
||||
// Write each constant pool item
|
||||
for (int n = 0 ; n < count ; n++) {
|
||||
list[n].write(env, out, this);
|
||||
}
|
||||
}
|
||||
|
||||
private
|
||||
static String sortKey(ConstantPoolData f) {
|
||||
if (f instanceof NumberConstantData) {
|
||||
Number num = ((NumberConstantData)f).num;
|
||||
String str = num.toString();
|
||||
int key = 3;
|
||||
if (num instanceof Integer) key = 0;
|
||||
else if (num instanceof Float) key = 1;
|
||||
else if (num instanceof Long) key = 2;
|
||||
return "\0" + (char)(str.length() + key<<8) + str;
|
||||
}
|
||||
if (f instanceof StringExpressionConstantData)
|
||||
return (String)((StringExpressionConstantData)f).str.getValue();
|
||||
if (f instanceof FieldConstantData) {
|
||||
MemberDefinition fd = ((FieldConstantData)f).field;
|
||||
return fd.getName()+" "+fd.getType().getTypeSignature()
|
||||
+" "+fd.getClassDeclaration().getName();
|
||||
}
|
||||
if (f instanceof NameAndTypeConstantData)
|
||||
return ((NameAndTypeConstantData)f).name+
|
||||
" "+((NameAndTypeConstantData)f).type;
|
||||
if (f instanceof ClassConstantData)
|
||||
return ((ClassConstantData)f).name;
|
||||
return ((StringConstantData)f).str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick sort an array of pool entries and a corresponding array of Strings
|
||||
* that are the sort keys for the field.
|
||||
*/
|
||||
private
|
||||
static void xsort(ConstantPoolData ff[], String ss[], int left, int right) {
|
||||
if (left >= right)
|
||||
return;
|
||||
String pivot = ss[left];
|
||||
int l = left;
|
||||
int r = right;
|
||||
while (l < r) {
|
||||
while (l <= right && ss[l].compareTo(pivot) <= 0)
|
||||
l++;
|
||||
while (r >= left && ss[r].compareTo(pivot) > 0)
|
||||
r--;
|
||||
if (l < r) {
|
||||
// swap items at l and at r
|
||||
ConstantPoolData def = ff[l];
|
||||
String name = ss[l];
|
||||
ff[l] = ff[r]; ff[r] = def;
|
||||
ss[l] = ss[r]; ss[r] = name;
|
||||
}
|
||||
}
|
||||
int middle = r;
|
||||
// swap left and middle
|
||||
ConstantPoolData def = ff[left];
|
||||
String name = ss[left];
|
||||
ff[left] = ff[middle]; ff[middle] = def;
|
||||
ss[left] = ss[middle]; ss[middle] = name;
|
||||
xsort(ff, ss, left, middle-1);
|
||||
xsort(ff, ss, middle + 1, right);
|
||||
}
|
||||
|
||||
}
|
||||
62
jdkSrc/jdk8/sun/tools/asm/ConstantPoolData.java
Normal file
62
jdkSrc/jdk8/sun/tools/asm/ConstantPoolData.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* Base constant data class. Every constant pool data item
|
||||
* is derived from this class.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
|
||||
abstract class ConstantPoolData implements RuntimeConstants {
|
||||
int index;
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
abstract void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException;
|
||||
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of entries that it takes up in the constant pool
|
||||
*/
|
||||
int width() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
46
jdkSrc/jdk8/sun/tools/asm/Cover.java
Normal file
46
jdkSrc/jdk8/sun/tools/asm/Cover.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
/**
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public class Cover {
|
||||
public int Type;
|
||||
public long Addr;
|
||||
public int NumCommand;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Cover(int type, long addr, int command) {
|
||||
Type=type;
|
||||
Addr=addr;
|
||||
NumCommand=command;
|
||||
}
|
||||
}
|
||||
77
jdkSrc/jdk8/sun/tools/asm/FieldConstantData.java
Normal file
77
jdkSrc/jdk8/sun/tools/asm/FieldConstantData.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* This is a field constant pool data item
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class FieldConstantData extends ConstantPoolData {
|
||||
MemberDefinition field;
|
||||
NameAndTypeData nt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
FieldConstantData(ConstantPool tab, MemberDefinition field) {
|
||||
this.field = field;
|
||||
nt = new NameAndTypeData(field);
|
||||
tab.put(field.getClassDeclaration());
|
||||
tab.put(nt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
if (field.isMethod()) {
|
||||
if (field.getClassDefinition().isInterface()) {
|
||||
out.writeByte(CONSTANT_INTERFACEMETHOD);
|
||||
} else {
|
||||
out.writeByte(CONSTANT_METHOD);
|
||||
}
|
||||
} else {
|
||||
out.writeByte(CONSTANT_FIELD);
|
||||
}
|
||||
out.writeShort(tab.index(field.getClassDeclaration()));
|
||||
out.writeShort(tab.index(nt));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
832
jdkSrc/jdk8/sun/tools/asm/Instruction.java
Normal file
832
jdkSrc/jdk8/sun/tools/asm/Instruction.java
Normal file
@@ -0,0 +1,832 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.util.Enumeration;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* An Java instruction
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public
|
||||
class Instruction implements Constants {
|
||||
long where;
|
||||
int pc;
|
||||
int opc;
|
||||
Object value;
|
||||
Instruction next;
|
||||
//JCOV
|
||||
boolean flagCondInverted; /* if true, the condition is reversed
|
||||
relatively of source code */
|
||||
boolean flagNoCovered = false; /* if true, the command will
|
||||
ignored for coverage */
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Instruction(long where, int opc, Object value, boolean flagCondInverted) {
|
||||
this.where = where;
|
||||
this.opc = opc;
|
||||
this.value = value;
|
||||
this.flagCondInverted = flagCondInverted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Instruction(boolean flagNoCovered, long where, int opc, Object value) {
|
||||
this.where = where;
|
||||
this.opc = opc;
|
||||
this.value = value;
|
||||
this.flagNoCovered = flagNoCovered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Instruction(long where, int opc, boolean flagNoCovered) {
|
||||
this.where = where;
|
||||
this.opc = opc;
|
||||
this.flagNoCovered = flagNoCovered;
|
||||
}
|
||||
//end JCOV
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Instruction(long where, int opc, Object value) {
|
||||
this.where = where;
|
||||
this.opc = opc;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* When deciding between a lookupswitch and a tableswitch, this
|
||||
* value is used in determining how much size increase is
|
||||
* acceptable.
|
||||
*/
|
||||
public static final double SWITCHRATIO;
|
||||
|
||||
static {
|
||||
// Set SWITCHRATIO from the property javac.switchratio
|
||||
// if it exists and is reasonable. Otherwise, set
|
||||
// SWITCHRATIO to 1.5, meaning that we will accept a 1.5x
|
||||
// blowup (for the instruction) to use a tableswitch instead
|
||||
// of a lookupswitch.
|
||||
double ratio = 1.5;
|
||||
String valStr = System.getProperty("javac.switchratio");
|
||||
if (valStr != null) {
|
||||
try {
|
||||
double temp = Double.valueOf(valStr).doubleValue();
|
||||
if (!(Double.isNaN(temp) || temp < 0.0)) {
|
||||
ratio = temp;
|
||||
}
|
||||
} catch (NumberFormatException ee) {}
|
||||
}
|
||||
SWITCHRATIO = ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor
|
||||
*/
|
||||
public int getOpcode() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optimize
|
||||
*/
|
||||
void optimize(Environment env) {
|
||||
switch (opc) {
|
||||
case opc_istore: case opc_lstore: case opc_fstore:
|
||||
case opc_dstore: case opc_astore:
|
||||
// Don't keep the LocalVariable info around, unless we
|
||||
// are actually going to generate a local variable table.
|
||||
if ((value instanceof LocalVariable) && !env.debug_vars()) {
|
||||
value = new Integer(((LocalVariable)value).slot);
|
||||
}
|
||||
break;
|
||||
|
||||
case opc_goto: {
|
||||
Label lbl = (Label)value;
|
||||
value = lbl = lbl.getDestination();
|
||||
if (lbl == next) {
|
||||
// goto to the next instruction, obsolete
|
||||
opc = opc_dead;
|
||||
break;
|
||||
}
|
||||
|
||||
// We optimize
|
||||
//
|
||||
// goto Tag
|
||||
// ...
|
||||
// Tag:
|
||||
// return
|
||||
//
|
||||
// except when we're generating debuggable code. When
|
||||
// we're generating debuggable code, we leave it alone,
|
||||
// in order to provide better stepping behavior. Consider
|
||||
// a method the end of which looks like this:
|
||||
//
|
||||
// ...
|
||||
// break;
|
||||
// } // end of loop
|
||||
// } // end of method
|
||||
//
|
||||
// If we optimize the goto away, we'll be left with a
|
||||
// single instruction (return) and the need to ascribe that
|
||||
// instruction to two source lines (the break statement and
|
||||
// the method's right curly). Can't get there from here.
|
||||
// Depending on which line-number ascription we choose, the
|
||||
// stepping user will step directly from the break statement
|
||||
// back into the caller of the method (case 1) or from the
|
||||
// statement that precedes the break statement to the method's
|
||||
// right curly (case 2). Similarly, he'll be able to set a
|
||||
// breakpoint on the break statement (case 1) or the method's
|
||||
// right curly (case 2), but not on both. Neither case 1 nor
|
||||
// case 2 is desirable. .We want him to see both the break
|
||||
// statement and the method's right curly when stepping,
|
||||
// and we want him to be able to set a breakpoint on either or
|
||||
// both. So we suppress the optimization when generating
|
||||
// debuggable code.
|
||||
// (Above notes from brucek@eng in JDK1.0.2, copied here
|
||||
// by kelly.ohair@eng for JDK1.1)
|
||||
//
|
||||
// With the changes to allow -O and -g at the same time,
|
||||
// I've changed the condition to be whether optimization is
|
||||
// on instead of the debugging flag being off.
|
||||
// - david.stoutamire@eng for 1.2
|
||||
|
||||
if (lbl.next != null && env.opt()) {
|
||||
switch (lbl.next.opc) {
|
||||
case opc_return: case opc_ireturn: case opc_lreturn:
|
||||
case opc_freturn: case opc_dreturn: case opc_areturn:
|
||||
// goto to return
|
||||
opc = lbl.next.opc;
|
||||
value = lbl.next.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_ifeq: case opc_ifne: case opc_ifgt:
|
||||
case opc_ifge: case opc_iflt: case opc_ifle:
|
||||
case opc_ifnull: case opc_ifnonnull:
|
||||
value = ((Label)value).getDestination();
|
||||
if (value == next) {
|
||||
// branch to next instruction, obsolete
|
||||
opc = opc_pop;
|
||||
break;
|
||||
}
|
||||
if ((next.opc == opc_goto) && (value == next.next)) {
|
||||
// Conditional branch over goto, invert
|
||||
// Note that you can't invert all conditions, condition
|
||||
// results for float/double compares are not invertable.
|
||||
switch (opc) {
|
||||
case opc_ifeq: opc = opc_ifne; break;
|
||||
case opc_ifne: opc = opc_ifeq; break;
|
||||
case opc_iflt: opc = opc_ifge; break;
|
||||
case opc_ifle: opc = opc_ifgt; break;
|
||||
case opc_ifgt: opc = opc_ifle; break;
|
||||
case opc_ifge: opc = opc_iflt; break;
|
||||
case opc_ifnull: opc = opc_ifnonnull; break;
|
||||
case opc_ifnonnull: opc = opc_ifnull; break;
|
||||
}
|
||||
//JCOV
|
||||
flagCondInverted = !flagCondInverted;
|
||||
//end JCOV
|
||||
value = next.value;
|
||||
next.opc = opc_dead;
|
||||
}
|
||||
break;
|
||||
|
||||
case opc_if_acmpeq: case opc_if_acmpne:
|
||||
case opc_if_icmpeq: case opc_if_icmpne:
|
||||
case opc_if_icmpgt: case opc_if_icmpge:
|
||||
case opc_if_icmplt: case opc_if_icmple:
|
||||
value = ((Label)value).getDestination();
|
||||
if (value == next) {
|
||||
// branch to next instruction, obsolete
|
||||
opc = opc_pop2;
|
||||
break;
|
||||
}
|
||||
if ((next.opc == opc_goto) && (value == next.next)) {
|
||||
// Conditional branch over goto, invert
|
||||
switch (opc) {
|
||||
case opc_if_acmpeq: opc = opc_if_acmpne; break;
|
||||
case opc_if_acmpne: opc = opc_if_acmpeq; break;
|
||||
case opc_if_icmpeq: opc = opc_if_icmpne; break;
|
||||
case opc_if_icmpne: opc = opc_if_icmpeq; break;
|
||||
case opc_if_icmpgt: opc = opc_if_icmple; break;
|
||||
case opc_if_icmpge: opc = opc_if_icmplt; break;
|
||||
case opc_if_icmplt: opc = opc_if_icmpge; break;
|
||||
case opc_if_icmple: opc = opc_if_icmpgt; break;
|
||||
}
|
||||
//JCOV
|
||||
flagCondInverted = !flagCondInverted;
|
||||
//end JCOV
|
||||
value = next.value;
|
||||
next.opc = opc_dead;
|
||||
}
|
||||
break;
|
||||
|
||||
case opc_tableswitch:
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)value;
|
||||
sw.defaultLabel = sw.defaultLabel.getDestination();
|
||||
for (Enumeration<Integer> e = sw.tab.keys() ; e.hasMoreElements() ; ) {
|
||||
Integer k = e.nextElement();
|
||||
Label lbl = sw.tab.get(k);
|
||||
sw.tab.put(k, lbl.getDestination());
|
||||
}
|
||||
|
||||
// Compute the approximate sizes of a tableswitch and a
|
||||
// lookupswitch. Decide which one we want to generate.
|
||||
|
||||
long range = (long)sw.maxValue - (long)sw.minValue + 1;
|
||||
long entries = sw.tab.size();
|
||||
|
||||
long tableSize = 4 + range;
|
||||
long lookupSize = 3 + 2 * entries;
|
||||
|
||||
if (tableSize <= lookupSize * SWITCHRATIO) {
|
||||
opc = opc_tableswitch;
|
||||
} else {
|
||||
opc = opc_lookupswitch;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect constants into the constant table
|
||||
*/
|
||||
void collect(ConstantPool tab) {
|
||||
switch (opc) {
|
||||
case opc_istore: case opc_lstore: case opc_fstore:
|
||||
case opc_dstore: case opc_astore:
|
||||
if (value instanceof LocalVariable) {
|
||||
MemberDefinition field = ((LocalVariable)value).field;
|
||||
tab.put(field.getName().toString());
|
||||
tab.put(field.getType().getTypeSignature());
|
||||
}
|
||||
return;
|
||||
|
||||
case opc_new: case opc_putfield:
|
||||
case opc_putstatic: case opc_getfield:
|
||||
case opc_getstatic: case opc_invokevirtual:
|
||||
case opc_invokespecial: case opc_invokestatic:
|
||||
case opc_invokeinterface: case opc_instanceof:
|
||||
case opc_checkcast:
|
||||
tab.put(value);
|
||||
return;
|
||||
|
||||
case opc_anewarray:
|
||||
tab.put(value);
|
||||
return;
|
||||
|
||||
case opc_multianewarray:
|
||||
tab.put(((ArrayData)value).type);
|
||||
return;
|
||||
|
||||
case opc_ldc:
|
||||
case opc_ldc_w:
|
||||
if (value instanceof Integer) {
|
||||
int v = ((Integer)value).intValue();
|
||||
if ((v >= -1) && (v <= 5)) {
|
||||
opc = opc_iconst_0 + v;
|
||||
return;
|
||||
} else if ((v >= -(1 << 7)) && (v < (1 << 7))) {
|
||||
opc = opc_bipush;
|
||||
return;
|
||||
} else if ((v >= -(1 << 15)) && (v < (1 << 15))) {
|
||||
opc = opc_sipush;
|
||||
return;
|
||||
}
|
||||
} else if (value instanceof Float) {
|
||||
float v = ((Float)value).floatValue();
|
||||
if (v == 0) {
|
||||
if (Float.floatToIntBits(v) == 0) {
|
||||
opc = opc_fconst_0;
|
||||
return;
|
||||
}
|
||||
} else if (v == 1) {
|
||||
opc = opc_fconst_1;
|
||||
return;
|
||||
} else if (v == 2) {
|
||||
opc = opc_fconst_2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
tab.put(value);
|
||||
return;
|
||||
|
||||
case opc_ldc2_w:
|
||||
if (value instanceof Long) {
|
||||
long v = ((Long)value).longValue();
|
||||
if (v == 0) {
|
||||
opc = opc_lconst_0;
|
||||
return;
|
||||
} else if (v == 1) {
|
||||
opc = opc_lconst_1;
|
||||
return;
|
||||
}
|
||||
} else if (value instanceof Double) {
|
||||
double v = ((Double)value).doubleValue();
|
||||
if (v == 0) {
|
||||
if (Double.doubleToLongBits(v) == 0) {
|
||||
opc = opc_dconst_0;
|
||||
return;
|
||||
}
|
||||
} else if (v == 1) {
|
||||
opc = opc_dconst_1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
tab.put(value);
|
||||
return;
|
||||
|
||||
case opc_try:
|
||||
for (Enumeration<CatchData> e = ((TryData)value).catches.elements() ; e.hasMoreElements() ;) {
|
||||
CatchData cd = e.nextElement();
|
||||
if (cd.getType() != null) {
|
||||
tab.put(cd.getType());
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case opc_nop:
|
||||
if ((value != null) && (value instanceof ClassDeclaration))
|
||||
tab.put(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Balance the stack
|
||||
*/
|
||||
int balance() {
|
||||
switch (opc) {
|
||||
case opc_dead: case opc_label: case opc_iinc:
|
||||
case opc_arraylength: case opc_laload: case opc_daload:
|
||||
case opc_nop: case opc_ineg: case opc_fneg:
|
||||
case opc_lneg: case opc_dneg: case opc_i2f:
|
||||
case opc_f2i: case opc_l2d: case opc_d2l:
|
||||
case opc_i2b: case opc_i2c: case opc_i2s:
|
||||
case opc_jsr: case opc_goto: case opc_jsr_w:
|
||||
case opc_goto_w: case opc_return: case opc_ret:
|
||||
case opc_instanceof: case opc_checkcast: case opc_newarray:
|
||||
case opc_anewarray: case opc_try: case opc_swap:
|
||||
return 0;
|
||||
|
||||
case opc_ldc: case opc_ldc_w: case opc_bipush:
|
||||
case opc_sipush: case opc_aconst_null: case opc_iconst_m1:
|
||||
case opc_iconst_0: case opc_iconst_1: case opc_iconst_2:
|
||||
case opc_iconst_3: case opc_iconst_4: case opc_iconst_5:
|
||||
case opc_fconst_0: case opc_fconst_1: case opc_fconst_2:
|
||||
case opc_iload: case opc_fload: case opc_aload:
|
||||
case opc_dup: case opc_dup_x1: case opc_dup_x2:
|
||||
case opc_i2l: case opc_i2d: case opc_f2l:
|
||||
case opc_f2d: case opc_new:
|
||||
return 1;
|
||||
|
||||
case opc_lload: case opc_dload: case opc_dup2:
|
||||
case opc_dup2_x1: case opc_dup2_x2: case opc_ldc2_w:
|
||||
case opc_lconst_0: case opc_lconst_1: case opc_dconst_0:
|
||||
case opc_dconst_1:
|
||||
return 2;
|
||||
|
||||
case opc_istore: case opc_fstore: case opc_astore:
|
||||
case opc_iaload: case opc_faload: case opc_aaload:
|
||||
case opc_baload: case opc_caload: case opc_saload:
|
||||
case opc_pop: case opc_iadd: case opc_fadd:
|
||||
case opc_isub: case opc_fsub: case opc_imul:
|
||||
case opc_fmul: case opc_idiv: case opc_fdiv:
|
||||
case opc_irem: case opc_frem: case opc_ishl:
|
||||
case opc_ishr: case opc_iushr: case opc_lshl:
|
||||
case opc_lshr: case opc_lushr: case opc_iand:
|
||||
case opc_ior: case opc_ixor: case opc_l2i:
|
||||
case opc_l2f: case opc_d2i: case opc_d2f:
|
||||
case opc_ifeq: case opc_ifne: case opc_iflt:
|
||||
case opc_ifle: case opc_ifgt: case opc_ifge:
|
||||
case opc_ifnull: case opc_ifnonnull: case opc_fcmpl:
|
||||
case opc_fcmpg: case opc_ireturn: case opc_freturn:
|
||||
case opc_areturn: case opc_tableswitch: case opc_lookupswitch:
|
||||
case opc_athrow: case opc_monitorenter: case opc_monitorexit:
|
||||
return -1;
|
||||
|
||||
case opc_lstore: case opc_dstore: case opc_pop2:
|
||||
case opc_ladd: case opc_dadd: case opc_lsub:
|
||||
case opc_dsub: case opc_lmul: case opc_dmul:
|
||||
case opc_ldiv: case opc_ddiv: case opc_lrem:
|
||||
case opc_drem: case opc_land: case opc_lor:
|
||||
case opc_lxor: case opc_if_acmpeq: case opc_if_acmpne:
|
||||
case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmplt:
|
||||
case opc_if_icmple: case opc_if_icmpgt: case opc_if_icmpge:
|
||||
case opc_lreturn: case opc_dreturn:
|
||||
return -2;
|
||||
|
||||
case opc_iastore: case opc_fastore: case opc_aastore:
|
||||
case opc_bastore: case opc_castore: case opc_sastore:
|
||||
case opc_lcmp: case opc_dcmpl: case opc_dcmpg:
|
||||
return -3;
|
||||
|
||||
case opc_lastore: case opc_dastore:
|
||||
return -4;
|
||||
|
||||
case opc_multianewarray:
|
||||
return 1 - ((ArrayData)value).nargs;
|
||||
|
||||
case opc_getfield:
|
||||
return ((MemberDefinition)value).getType().stackSize() - 1;
|
||||
|
||||
case opc_putfield:
|
||||
return -1 - ((MemberDefinition)value).getType().stackSize();
|
||||
|
||||
case opc_getstatic:
|
||||
return ((MemberDefinition)value).getType().stackSize();
|
||||
|
||||
case opc_putstatic:
|
||||
return -((MemberDefinition)value).getType().stackSize();
|
||||
|
||||
case opc_invokevirtual:
|
||||
case opc_invokespecial:
|
||||
case opc_invokeinterface:
|
||||
return ((MemberDefinition)value).getType().getReturnType().stackSize() -
|
||||
(((MemberDefinition)value).getType().stackSize() + 1);
|
||||
|
||||
case opc_invokestatic:
|
||||
return ((MemberDefinition)value).getType().getReturnType().stackSize() -
|
||||
(((MemberDefinition)value).getType().stackSize());
|
||||
}
|
||||
throw new CompilerError("invalid opcode: " + toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size of the instruction
|
||||
*/
|
||||
int size(ConstantPool tab) {
|
||||
switch (opc) {
|
||||
case opc_try: case opc_label: case opc_dead:
|
||||
return 0;
|
||||
|
||||
case opc_bipush: case opc_newarray:
|
||||
return 2;
|
||||
|
||||
case opc_sipush: case opc_goto: case opc_jsr:
|
||||
case opc_ifeq: case opc_ifne: case opc_ifgt:
|
||||
case opc_ifge: case opc_iflt: case opc_ifle:
|
||||
case opc_ifnull: case opc_ifnonnull: case opc_if_acmpeq:
|
||||
case opc_if_acmpne: case opc_if_icmpeq: case opc_if_icmpne:
|
||||
case opc_if_icmpgt: case opc_if_icmpge: case opc_if_icmplt:
|
||||
case opc_if_icmple:
|
||||
return 3;
|
||||
|
||||
case opc_ldc:
|
||||
case opc_ldc_w:
|
||||
if (tab.index(value) < 256) {
|
||||
opc = opc_ldc;
|
||||
return 2;
|
||||
} else {
|
||||
opc = opc_ldc_w;
|
||||
return 3;
|
||||
}
|
||||
|
||||
case opc_iload: case opc_lload: case opc_fload:
|
||||
case opc_dload: case opc_aload: {
|
||||
int v = ((Number)value).intValue();
|
||||
if (v < 4) {
|
||||
if (v < 0) {
|
||||
throw new CompilerError("invalid slot: " + toString()
|
||||
+ "\nThis error possibly resulted from poorly constructed class paths.");
|
||||
}
|
||||
opc = opc_iload_0 + (opc - opc_iload) * 4 + v;
|
||||
return 1;
|
||||
} else if (v <= 255) {
|
||||
return 2;
|
||||
} else {
|
||||
opc += 256; // indicate wide variant
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
case opc_iinc: {
|
||||
int register = ((int[])value)[0];
|
||||
int increment = ((int[])value)[1];
|
||||
if (register < 0) {
|
||||
throw new CompilerError("invalid slot: " + toString());
|
||||
}
|
||||
if (register <= 255 && (((byte)increment) == increment)) {
|
||||
return 3;
|
||||
} else {
|
||||
opc += 256; // indicate wide variant
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
case opc_istore: case opc_lstore: case opc_fstore:
|
||||
case opc_dstore: case opc_astore: {
|
||||
int v = (value instanceof Number) ?
|
||||
((Number)value).intValue() : ((LocalVariable)value).slot;
|
||||
if (v < 4) {
|
||||
if (v < 0) {
|
||||
throw new CompilerError("invalid slot: " + toString());
|
||||
}
|
||||
opc = opc_istore_0 + (opc - opc_istore) * 4 + v;
|
||||
return 1;
|
||||
} else if (v <= 255) {
|
||||
return 2;
|
||||
} else {
|
||||
opc += 256; // indicate wide variant
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
case opc_ret: {
|
||||
int v = ((Number)value).intValue();
|
||||
if (v <= 255) {
|
||||
if (v < 0) {
|
||||
throw new CompilerError("invalid slot: " + toString());
|
||||
}
|
||||
return 2;
|
||||
} else {
|
||||
opc += 256; // indicate wide variant
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
case opc_ldc2_w: case opc_new:
|
||||
case opc_putstatic: case opc_getstatic:
|
||||
case opc_putfield: case opc_getfield:
|
||||
case opc_invokevirtual: case opc_invokespecial:
|
||||
case opc_invokestatic: case opc_instanceof:
|
||||
case opc_checkcast: case opc_anewarray:
|
||||
return 3;
|
||||
|
||||
case opc_multianewarray:
|
||||
return 4;
|
||||
|
||||
case opc_invokeinterface:
|
||||
case opc_goto_w:
|
||||
case opc_jsr_w:
|
||||
return 5;
|
||||
|
||||
case opc_tableswitch: {
|
||||
SwitchData sw = (SwitchData)value;
|
||||
int n = 1;
|
||||
for(; ((pc + n) % 4) != 0 ; n++);
|
||||
return n + 16 + (sw.maxValue - sw.minValue) * 4;
|
||||
}
|
||||
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)value;
|
||||
int n = 1;
|
||||
for(; ((pc + n) % 4) != 0 ; n++);
|
||||
return n + 8 + sw.tab.size() * 8;
|
||||
}
|
||||
|
||||
case opc_nop:
|
||||
if ((value != null) && !(value instanceof Integer))
|
||||
return 2;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
// most opcodes are only 1 byte long
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate code
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
void write(DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
switch (opc) {
|
||||
case opc_try: case opc_label: case opc_dead:
|
||||
break;
|
||||
|
||||
case opc_bipush: case opc_newarray:
|
||||
case opc_iload: case opc_lload: case opc_fload:
|
||||
case opc_dload: case opc_aload: case opc_ret:
|
||||
out.writeByte(opc);
|
||||
out.writeByte(((Number)value).intValue());
|
||||
break;
|
||||
|
||||
case opc_iload + 256: case opc_lload + 256:
|
||||
case opc_fload + 256: case opc_dload + 256:
|
||||
case opc_aload + 256: case opc_ret + 256:
|
||||
out.writeByte(opc_wide);
|
||||
out.writeByte(opc - 256);
|
||||
out.writeShort(((Number)value).intValue());
|
||||
break;
|
||||
|
||||
case opc_istore: case opc_lstore: case opc_fstore:
|
||||
case opc_dstore: case opc_astore:
|
||||
out.writeByte(opc);
|
||||
out.writeByte((value instanceof Number) ?
|
||||
((Number)value).intValue() : ((LocalVariable)value).slot);
|
||||
break;
|
||||
|
||||
case opc_istore + 256: case opc_lstore + 256:
|
||||
case opc_fstore + 256: case opc_dstore + 256:
|
||||
case opc_astore + 256:
|
||||
out.writeByte(opc_wide);
|
||||
out.writeByte(opc - 256);
|
||||
out.writeShort((value instanceof Number) ?
|
||||
((Number)value).intValue() : ((LocalVariable)value).slot);
|
||||
break;
|
||||
|
||||
case opc_sipush:
|
||||
out.writeByte(opc);
|
||||
out.writeShort(((Number)value).intValue());
|
||||
break;
|
||||
|
||||
case opc_ldc:
|
||||
out.writeByte(opc);
|
||||
out.writeByte(tab.index(value));
|
||||
break;
|
||||
|
||||
case opc_ldc_w: case opc_ldc2_w:
|
||||
case opc_new: case opc_putstatic:
|
||||
case opc_getstatic: case opc_putfield:
|
||||
case opc_getfield: case opc_invokevirtual:
|
||||
case opc_invokespecial: case opc_invokestatic:
|
||||
case opc_instanceof: case opc_checkcast:
|
||||
out.writeByte(opc);
|
||||
out.writeShort(tab.index(value));
|
||||
break;
|
||||
|
||||
case opc_iinc:
|
||||
out.writeByte(opc);
|
||||
out.writeByte(((int[])value)[0]); // register
|
||||
out.writeByte(((int[])value)[1]); // increment
|
||||
break;
|
||||
|
||||
case opc_iinc + 256:
|
||||
out.writeByte(opc_wide);
|
||||
out.writeByte(opc - 256);
|
||||
out.writeShort(((int[])value)[0]); // register
|
||||
out.writeShort(((int[])value)[1]); // increment
|
||||
break;
|
||||
|
||||
case opc_anewarray:
|
||||
out.writeByte(opc);
|
||||
out.writeShort(tab.index(value));
|
||||
break;
|
||||
|
||||
case opc_multianewarray:
|
||||
out.writeByte(opc);
|
||||
out.writeShort(tab.index(((ArrayData)value).type));
|
||||
out.writeByte(((ArrayData)value).nargs);
|
||||
break;
|
||||
|
||||
case opc_invokeinterface:
|
||||
out.writeByte(opc);
|
||||
out.writeShort(tab.index(value));
|
||||
out.writeByte(((MemberDefinition)value).getType().stackSize() + 1);
|
||||
out.writeByte(0);
|
||||
break;
|
||||
|
||||
case opc_goto: case opc_jsr: case opc_ifeq:
|
||||
case opc_ifne: case opc_ifgt: case opc_ifge:
|
||||
case opc_iflt: case opc_ifle: case opc_ifnull:
|
||||
case opc_ifnonnull: case opc_if_acmpeq: case opc_if_acmpne:
|
||||
case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpgt:
|
||||
case opc_if_icmpge: case opc_if_icmplt: case opc_if_icmple:
|
||||
out.writeByte(opc);
|
||||
out.writeShort(((Instruction)value).pc - pc);
|
||||
break;
|
||||
|
||||
case opc_goto_w:
|
||||
case opc_jsr_w:
|
||||
out.writeByte(opc);
|
||||
out.writeLong(((Instruction)value).pc - pc);
|
||||
break;
|
||||
|
||||
case opc_tableswitch: {
|
||||
SwitchData sw = (SwitchData)value;
|
||||
out.writeByte(opc);
|
||||
for(int n = 1 ; ((pc + n) % 4) != 0 ; n++) {
|
||||
out.writeByte(0);
|
||||
}
|
||||
out.writeInt(sw.defaultLabel.pc - pc);
|
||||
out.writeInt(sw.minValue);
|
||||
out.writeInt(sw.maxValue);
|
||||
for (int n = sw.minValue ; n <= sw.maxValue ; n++) {
|
||||
Label lbl = sw.get(n);
|
||||
int target_pc = (lbl != null) ? lbl.pc : sw.defaultLabel.pc;
|
||||
out.writeInt(target_pc - pc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_lookupswitch: {
|
||||
SwitchData sw = (SwitchData)value;
|
||||
out.writeByte(opc);
|
||||
int n = pc + 1;
|
||||
for(; (n % 4) != 0 ; n++) {
|
||||
out.writeByte(0);
|
||||
}
|
||||
out.writeInt(sw.defaultLabel.pc - pc);
|
||||
out.writeInt(sw.tab.size());
|
||||
for (Enumeration<Integer> e = sw.sortedKeys(); e.hasMoreElements() ; ) {
|
||||
Integer v = e.nextElement();
|
||||
out.writeInt(v.intValue());
|
||||
out.writeInt(sw.get(v).pc - pc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case opc_nop:
|
||||
if (value != null) {
|
||||
if (value instanceof Integer)
|
||||
out.writeByte(((Integer)value).intValue());
|
||||
else
|
||||
out.writeShort(tab.index(value));
|
||||
return;
|
||||
}
|
||||
// fall through
|
||||
|
||||
default:
|
||||
out.writeByte(opc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toString
|
||||
*/
|
||||
public String toString() {
|
||||
String prefix = (where >> WHEREOFFSETBITS) + ":\t";
|
||||
switch (opc) {
|
||||
case opc_try:
|
||||
return prefix + "try " + ((TryData)value).getEndLabel().hashCode();
|
||||
|
||||
case opc_dead:
|
||||
return prefix + "dead";
|
||||
|
||||
case opc_iinc: {
|
||||
int register = ((int[])value)[0];
|
||||
int increment = ((int[])value)[1];
|
||||
return prefix + opcNames[opc] + " " + register + ", " + increment;
|
||||
}
|
||||
|
||||
default:
|
||||
if (value != null) {
|
||||
if (value instanceof Label) {
|
||||
return prefix + opcNames[opc] + " " + value.toString();
|
||||
} else if (value instanceof Instruction) {
|
||||
return prefix + opcNames[opc] + " " + value.hashCode();
|
||||
} else if (value instanceof String) {
|
||||
return prefix + opcNames[opc] + " \"" + value + "\"";
|
||||
} else {
|
||||
return prefix + opcNames[opc] + " " + value;
|
||||
}
|
||||
} else {
|
||||
return prefix + opcNames[opc];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
jdkSrc/jdk8/sun/tools/asm/Label.java
Normal file
117
jdkSrc/jdk8/sun/tools/asm/Label.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.MemberDefinition;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* A label instruction. This is a 0 size instruction.
|
||||
* It is the only valid target of a branch instruction.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public final
|
||||
class Label extends Instruction {
|
||||
static int labelCount = 0;
|
||||
int ID;
|
||||
int depth;
|
||||
MemberDefinition locals[];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Label() {
|
||||
super(0, opc_label, null);
|
||||
this.ID = ++labelCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the final destination, eliminate jumps gotos, and jumps to
|
||||
* labels that are immediately folowed by another label. The depth
|
||||
* field is used to leave bread crumbs to avoid infinite loops.
|
||||
*/
|
||||
Label getDestination() {
|
||||
Label lbl = this;
|
||||
if ((next != null) && (next != this) && (depth == 0)) {
|
||||
depth = 1;
|
||||
|
||||
switch (next.opc) {
|
||||
case opc_label:
|
||||
lbl = ((Label)next).getDestination();
|
||||
break;
|
||||
|
||||
case opc_goto:
|
||||
lbl = ((Label)next.value).getDestination();
|
||||
break;
|
||||
|
||||
case opc_ldc:
|
||||
case opc_ldc_w:
|
||||
if (next.value instanceof Integer) {
|
||||
Instruction inst = next.next;
|
||||
if (inst.opc == opc_label) {
|
||||
inst = ((Label)inst).getDestination().next;
|
||||
}
|
||||
|
||||
if (inst.opc == opc_ifeq) {
|
||||
if (((Integer)next.value).intValue() == 0) {
|
||||
lbl = (Label)inst.value;
|
||||
} else {
|
||||
lbl = new Label();
|
||||
lbl.next = inst.next;
|
||||
inst.next = lbl;
|
||||
}
|
||||
lbl = lbl.getDestination();
|
||||
break;
|
||||
}
|
||||
if (inst.opc == opc_ifne) {
|
||||
if (((Integer)next.value).intValue() == 0) {
|
||||
lbl = new Label();
|
||||
lbl.next = inst.next;
|
||||
inst.next = lbl;
|
||||
} else {
|
||||
lbl = (Label)inst.value;
|
||||
}
|
||||
lbl = lbl.getDestination();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
depth = 0;
|
||||
}
|
||||
return lbl;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String s = "$" + ID + ":";
|
||||
if (value != null)
|
||||
s = s + " stack=" + value;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
66
jdkSrc/jdk8/sun/tools/asm/LocalVariable.java
Normal file
66
jdkSrc/jdk8/sun/tools/asm/LocalVariable.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
|
||||
/**
|
||||
* This class is used to assemble the local variables in the local
|
||||
* variable table.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*
|
||||
* @author Arthur van Hoff
|
||||
*/
|
||||
public final
|
||||
class LocalVariable {
|
||||
MemberDefinition field;
|
||||
int slot;
|
||||
int from;
|
||||
int to;
|
||||
|
||||
public LocalVariable(MemberDefinition field, int slot) {
|
||||
if (field == null) {
|
||||
new Exception().printStackTrace();
|
||||
}
|
||||
this.field = field;
|
||||
this.slot = slot;
|
||||
to = -1;
|
||||
}
|
||||
|
||||
LocalVariable(MemberDefinition field, int slot, int from, int to) {
|
||||
this.field = field;
|
||||
this.slot = slot;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return field + "/" + slot;
|
||||
}
|
||||
}
|
||||
132
jdkSrc/jdk8/sun/tools/asm/LocalVariableTable.java
Normal file
132
jdkSrc/jdk8/sun/tools/asm/LocalVariableTable.java
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* This class is used to assemble the local variable table.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*
|
||||
* @author Arthur van Hoff
|
||||
*/
|
||||
final
|
||||
class LocalVariableTable {
|
||||
LocalVariable locals[] = new LocalVariable[8];
|
||||
int len;
|
||||
|
||||
/**
|
||||
* Define a new local variable. Merge entries where possible.
|
||||
*/
|
||||
void define(MemberDefinition field, int slot, int from, int to) {
|
||||
if (from >= to) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
if ((locals[i].field == field) && (locals[i].slot == slot) &&
|
||||
(from <= locals[i].to) && (to >= locals[i].from)) {
|
||||
locals[i].from = Math.min(locals[i].from, from);
|
||||
locals[i].to = Math.max(locals[i].to, to);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (len == locals.length) {
|
||||
LocalVariable newlocals[] = new LocalVariable[len * 2];
|
||||
System.arraycopy(locals, 0, newlocals, 0, len);
|
||||
locals = newlocals;
|
||||
}
|
||||
locals[len++] = new LocalVariable(field, slot, from, to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim overlapping local ranges. Java forbids shadowing of
|
||||
* locals in nested scopes, but non-nested scopes may still declare
|
||||
* locals with the same name. Because local variable ranges are
|
||||
* computed using flow analysis as part of assembly, it isn't
|
||||
* possible to simply make sure variable ranges end where the
|
||||
* enclosing lexical scope ends. This method makes sure that
|
||||
* variables with the same name don't overlap, giving priority to
|
||||
* fields with higher slot numbers that should have appeared later
|
||||
* in the source.
|
||||
*/
|
||||
private void trim_ranges() {
|
||||
for (int i=0; i<len; i++) {
|
||||
for (int j=i+1; j<len; j++) {
|
||||
if ((locals[i].field.getName()==locals[j].field.getName())
|
||||
&& (locals[i].from <= locals[j].to)
|
||||
&& (locals[i].to >= locals[j].from)) {
|
||||
// At this point we know that both ranges are
|
||||
// the same name and there is also overlap or they abut
|
||||
if (locals[i].slot < locals[j].slot) {
|
||||
if (locals[i].from < locals[j].from) {
|
||||
locals[i].to = Math.min(locals[i].to, locals[j].from);
|
||||
} else {
|
||||
// We've detected two local variables with the
|
||||
// same name, and the one with the greater slot
|
||||
// number starts before the other. This order
|
||||
// reversal may happen with locals with the same
|
||||
// name declared in both a try body and an
|
||||
// associated catch clause. This is rare, and
|
||||
// we give up.
|
||||
}
|
||||
} else if (locals[i].slot > locals[j].slot) {
|
||||
if (locals[i].from > locals[j].from) {
|
||||
locals[j].to = Math.min(locals[j].to, locals[i].from);
|
||||
} else {
|
||||
// Same situation as above; just give up.
|
||||
}
|
||||
} else {
|
||||
// This case can happen if there are two variables
|
||||
// with the same name and slot numbers, and ranges
|
||||
// that abut. AFAIK the only way this can occur
|
||||
// is with multiple static initializers. Punt.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out the data.
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
trim_ranges();
|
||||
out.writeShort(len);
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
//System.out.println("pc=" + locals[i].from + ", len=" + (locals[i].to - locals[i].from) + ", nm=" + locals[i].field.getName() + ", slot=" + locals[i].slot);
|
||||
out.writeShort(locals[i].from);
|
||||
out.writeShort(locals[i].to - locals[i].from);
|
||||
out.writeShort(tab.index(locals[i].field.getName().toString()));
|
||||
out.writeShort(tab.index(locals[i].field.getType().getTypeSignature()));
|
||||
out.writeShort(locals[i].slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
jdkSrc/jdk8/sun/tools/asm/NameAndTypeConstantData.java
Normal file
69
jdkSrc/jdk8/sun/tools/asm/NameAndTypeConstantData.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* This is a name and type constant pool data item
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class NameAndTypeConstantData extends ConstantPoolData {
|
||||
String name;
|
||||
String type;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
NameAndTypeConstantData(ConstantPool tab, NameAndTypeData nt) {
|
||||
name = nt.field.getName().toString();
|
||||
type = nt.field.getType().getTypeSignature();
|
||||
tab.put(name);
|
||||
tab.put(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
out.writeByte(CONSTANT_NAMEANDTYPE);
|
||||
out.writeShort(tab.index(name));
|
||||
out.writeShort(tab.index(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
73
jdkSrc/jdk8/sun/tools/asm/NameAndTypeData.java
Normal file
73
jdkSrc/jdk8/sun/tools/asm/NameAndTypeData.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
|
||||
/**
|
||||
* An object to represent a name and type constant pool data item.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class NameAndTypeData {
|
||||
MemberDefinition field;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
NameAndTypeData(MemberDefinition field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashcode
|
||||
*/
|
||||
public int hashCode() {
|
||||
return field.getName().hashCode() * field.getType().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Equality
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if ((obj != null) && (obj instanceof NameAndTypeData)) {
|
||||
NameAndTypeData nt = (NameAndTypeData)obj;
|
||||
return field.getName().equals(nt.field.getName()) &&
|
||||
field.getType().equals(nt.field.getType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to string
|
||||
*/
|
||||
public String toString() {
|
||||
return "%%" + field.toString() + "%%";
|
||||
}
|
||||
}
|
||||
81
jdkSrc/jdk8/sun/tools/asm/NumberConstantData.java
Normal file
81
jdkSrc/jdk8/sun/tools/asm/NumberConstantData.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* A numeric constant pool item. Can either be integer, float, long or double.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class NumberConstantData extends ConstantPoolData {
|
||||
Number num;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
NumberConstantData(ConstantPool tab, Number num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
if (num instanceof Integer) {
|
||||
out.writeByte(CONSTANT_INTEGER);
|
||||
out.writeInt(num.intValue());
|
||||
} else if (num instanceof Long) {
|
||||
out.writeByte(CONSTANT_LONG);
|
||||
out.writeLong(num.longValue());
|
||||
} else if (num instanceof Float) {
|
||||
out.writeByte(CONSTANT_FLOAT);
|
||||
out.writeFloat(num.floatValue());
|
||||
} else if (num instanceof Double) {
|
||||
out.writeByte(CONSTANT_DOUBLE);
|
||||
out.writeDouble(num.doubleValue());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return (width() == 1) ? 0 : 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of entries that it takes up in the constant pool
|
||||
*/
|
||||
int width() {
|
||||
return ((num instanceof Double) || (num instanceof Long)) ? 2 : 1;
|
||||
}
|
||||
}
|
||||
71
jdkSrc/jdk8/sun/tools/asm/StringConstantData.java
Normal file
71
jdkSrc/jdk8/sun/tools/asm/StringConstantData.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* This is a string constant pool data item.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class StringConstantData extends ConstantPoolData {
|
||||
String str;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
StringConstantData(ConstantPool tab, String str) {
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
out.writeByte(CONSTANT_UTF8);
|
||||
out.writeUTF(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* toString
|
||||
*/
|
||||
public String toString() {
|
||||
return "StringConstantData[" + str + "]=" + str.hashCode();
|
||||
}
|
||||
}
|
||||
74
jdkSrc/jdk8/sun/tools/asm/StringExpressionConstantData.java
Normal file
74
jdkSrc/jdk8/sun/tools/asm/StringExpressionConstantData.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import sun.tools.tree.StringExpression;
|
||||
import java.io.IOException;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
/**
|
||||
* This is a string expression constant. This constant
|
||||
* represents an Java string constant.
|
||||
*
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
final
|
||||
class StringExpressionConstantData extends ConstantPoolData {
|
||||
StringExpression str;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
StringExpressionConstantData(ConstantPool tab, StringExpression str) {
|
||||
this.str = str;
|
||||
tab.put(str.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the constant to the output stream
|
||||
*/
|
||||
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
|
||||
out.writeByte(CONSTANT_STRING);
|
||||
out.writeShort(tab.index(str.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the order of the constant
|
||||
*/
|
||||
int order() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* toString
|
||||
*/
|
||||
public String toString() {
|
||||
return "StringExpressionConstantData[" + str.getValue() + "]=" + str.getValue().hashCode();
|
||||
}
|
||||
}
|
||||
149
jdkSrc/jdk8/sun/tools/asm/SwitchData.java
Normal file
149
jdkSrc/jdk8/sun/tools/asm/SwitchData.java
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public final
|
||||
class SwitchData {
|
||||
int minValue, maxValue;
|
||||
Label defaultLabel = new Label();
|
||||
Hashtable<Integer,Label> tab = new Hashtable<>();
|
||||
// JCOV
|
||||
Hashtable<Integer,Long> whereCaseTab = null;
|
||||
// end JCOV
|
||||
|
||||
/**
|
||||
* Get a label
|
||||
*/
|
||||
public Label get(int n) {
|
||||
return tab.get(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a label
|
||||
*/
|
||||
public Label get(Integer n) {
|
||||
return tab.get(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label
|
||||
*/
|
||||
public void add(int n, Label lbl) {
|
||||
if (tab.size() == 0) {
|
||||
minValue = n;
|
||||
maxValue = n;
|
||||
} else {
|
||||
if (n < minValue) {
|
||||
minValue = n;
|
||||
}
|
||||
if (n > maxValue) {
|
||||
maxValue = n;
|
||||
}
|
||||
}
|
||||
tab.put(Integer.valueOf(n), lbl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default label
|
||||
*/
|
||||
public Label getDefaultLabel() {
|
||||
return defaultLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the keys of this enumaration sorted in ascending order
|
||||
*/
|
||||
public synchronized Enumeration<Integer> sortedKeys() {
|
||||
return new SwitchDataEnumeration(tab);
|
||||
}
|
||||
|
||||
// JCOV
|
||||
public void initTableCase() {
|
||||
whereCaseTab = new Hashtable<Integer,Long>();
|
||||
}
|
||||
public void addTableCase(int index, long where) {
|
||||
if (whereCaseTab != null)
|
||||
whereCaseTab.put(Integer.valueOf(index), Long.valueOf(where));
|
||||
}
|
||||
// this puts String key into Hashtable<Integer,Long>
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addTableDefault(long where) {
|
||||
if (whereCaseTab != null)
|
||||
((Hashtable)whereCaseTab).put("default", Long.valueOf(where));
|
||||
}
|
||||
public long whereCase(Object key) {
|
||||
Long i = whereCaseTab.get(key);
|
||||
return (i == null) ? 0L : i.longValue();
|
||||
}
|
||||
public boolean getDefault() {
|
||||
return (whereCase("default") != 0L);
|
||||
}
|
||||
// end JCOV
|
||||
}
|
||||
|
||||
class SwitchDataEnumeration implements Enumeration<Integer> {
|
||||
private Integer table[];
|
||||
private int current_index = 0;
|
||||
|
||||
/**
|
||||
* Create a new enumeration from the hashtable. Each key in the
|
||||
* hash table will be an Integer, with the value being a label. The
|
||||
* enumeration returns the keys in sorted order.
|
||||
*/
|
||||
SwitchDataEnumeration(Hashtable<Integer,Label> tab) {
|
||||
table = new Integer[tab.size()];
|
||||
int i = 0;
|
||||
for (Enumeration<Integer> e = tab.keys() ; e.hasMoreElements() ; ) {
|
||||
table[i++] = e.nextElement();
|
||||
}
|
||||
Arrays.sort(table);
|
||||
current_index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are there more keys to return?
|
||||
*/
|
||||
public boolean hasMoreElements() {
|
||||
return current_index < table.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next key.
|
||||
*/
|
||||
public Integer nextElement() {
|
||||
return table[current_index++];
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/sun/tools/asm/TryData.java
Normal file
63
jdkSrc/jdk8/sun/tools/asm/TryData.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.tools.asm;
|
||||
|
||||
import sun.tools.java.*;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* WARNING: The contents of this source file are not part of any
|
||||
* supported API. Code that depends on them does so at its own risk:
|
||||
* they are subject to change or removal without notice.
|
||||
*/
|
||||
public final
|
||||
class TryData {
|
||||
Vector<CatchData> catches = new Vector<>();
|
||||
Label endLabel = new Label();
|
||||
|
||||
/**
|
||||
* Add a label
|
||||
*/
|
||||
public CatchData add(Object type) {
|
||||
CatchData cd = new CatchData(type);
|
||||
catches.addElement(cd);
|
||||
return cd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a label
|
||||
*/
|
||||
public CatchData getCatch(int n) {
|
||||
return catches.elementAt(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default label
|
||||
*/
|
||||
public Label getEndLabel() {
|
||||
return endLabel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user