From: <cap...@us...> - 2009-01-02 00:18:26
|
Revision: 15248 http://jikesrvm.svn.sourceforge.net/jikesrvm/?rev=15248&view=rev Author: captain5050 Date: 2009-01-02 00:18:20 +0000 (Fri, 02 Jan 2009) Log Message: ----------- RVM-737: support for local variable tables by Suriya Subramanian. Modified Paths: -------------- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/NormalMethod.java rvmroot/trunk/rvm/src/org/jikesrvm/classloader/RVMMethod.java Added Paths: ----------- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/LocalVariableTable.java Added: rvmroot/trunk/rvm/src/org/jikesrvm/classloader/LocalVariableTable.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/LocalVariableTable.java (rev 0) +++ rvmroot/trunk/rvm/src/org/jikesrvm/classloader/LocalVariableTable.java 2009-01-02 00:18:20 UTC (rev 15248) @@ -0,0 +1,129 @@ +/* + * This file is part of the Jikes RVM project (http://jikesrvm.org). + * + * This file is licensed to You under the Common Public License (CPL); + * You may not use this file except in compliance with the License. You + * may obtain a copy of the License at + * + * http://www.opensource.org/licenses/cpl1.0.php + * + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. + */ +package org.jikesrvm.classloader; + +import java.io.DataInputStream; +import java.io.IOException; + +/** + * A java method's local variable information + */ +public final class LocalVariableTable { + /** + * Local variables in this table + */ + private final LocalVariable[] locals; + + /** + * Information needed to describe a local variable + */ + static class LocalVariable { + /** + * The start PC location where the variable is active + */ + private final int startPC; + + /** + * The variable is active in PC values [startPC, startPC+length]. + */ + private final int length; + + /** + * The variable's name. + */ + private final Atom name; + + /** + * The variable's type descriptor. + */ + private final Atom descriptor; + + /** + * The slot on the local variable stack where the variable is stored. + */ + private final int frameIndex; + + /** + * Construct a local variable. + * + * @param startPC + * @param length + * @param name + * @param descriptor + * @param frameIndex + */ + LocalVariable(int startPC, int length, Atom name, Atom descriptor, int frameIndex) { + this.startPC = startPC; + this.length = length; + this.name = name; + this.descriptor = descriptor; + this.frameIndex = frameIndex; + } + + /** + * String represenation of this local variable. + */ + public String toString() { + return (startPC + " " + + length + " " + + name.toString() + " " + + descriptor.toString() + " " + + frameIndex + "\n"); + } + } + + /** + * Construct the local variable table + * + * @param locals + */ + LocalVariableTable(LocalVariable[] locals) { + this.locals = locals; + } + + /** + * Read the local variable table + * + * @return a local variable table or null if none were present + */ + static LocalVariableTable readLocalVariableTable(DataInputStream input, int[] constantPool) throws IOException { + int numVars = input.readUnsignedShort(); + if (numVars > 0) { + LocalVariable[] lvs = new LocalVariable[numVars]; + for (int i = 0; i < numVars; ++i) { + LocalVariable lv = new LocalVariable( + input.readUnsignedShort(), + input.readUnsignedShort(), + RVMClass.getUtf(constantPool, input.readUnsignedShort()), + RVMClass.getUtf(constantPool, input.readUnsignedShort()), + input.readUnsignedShort()); + lvs[i] = lv; + } + return new LocalVariableTable(lvs); + } else { + return null; + } + } + + /** + * String representation of the local variable table. + */ + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Local Variable Table: \n"); + for (LocalVariable lv : locals) { + sb.append(lv.toString()); + } + return sb.toString(); + } +} Modified: rvmroot/trunk/rvm/src/org/jikesrvm/classloader/NormalMethod.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/NormalMethod.java 2009-01-01 23:41:31 UTC (rev 15247) +++ rvmroot/trunk/rvm/src/org/jikesrvm/classloader/NormalMethod.java 2009-01-02 00:18:20 UTC (rev 15248) @@ -121,6 +121,11 @@ */ private final int[] lineNumberMap; + /** + * the local variable table + */ + private static final HashMapRVM<NormalMethod, LocalVariableTable> localVariableTables = new HashMapRVM<NormalMethod, LocalVariableTable>(); + // Extra fields for on-stack replacement /** Possible OSR bytecode array consisting of prologue and original bytecodes */ private static final HashMapRVM<NormalMethod, byte[]> synthesizedBytecodes = @@ -147,6 +152,7 @@ * @param bc the bytecodes of this method * @param eMap the exception handler map for this method * @param lm the line number map for this method + * @param lvt the local variable table for this method * @param constantPool the constantPool for this method * @param sig generic type of this method. * @param annotations array of runtime visible annotations @@ -154,7 +160,7 @@ * @param ad annotation default value for that appears in annotation classes */ NormalMethod(TypeReference dc, MemberReference mr, short mo, TypeReference[] et, short lw, short ow, - byte[] bc, ExceptionHandlerMap eMap, int[] lm, int[] constantPool, Atom sig, + byte[] bc, ExceptionHandlerMap eMap, int[] lm, LocalVariableTable lvt, int[] constantPool, Atom sig, RVMAnnotation[] annotations, RVMAnnotation[][] parameterAnnotations, Object ad) { super(dc, mr, mo, et, sig, annotations, parameterAnnotations, ad); localWords = lw; @@ -162,6 +168,7 @@ bytecodes = bc; exceptionHandlerMap = eMap; lineNumberMap = lm; + localVariableTables.put(this, lvt); computeSummary(constantPool); } @@ -785,4 +792,11 @@ summarySize = (char) calleeSize; } } + + /** + * @return LocalVariableTable associated with this method + */ + public LocalVariableTable getLocalVariableTable() { + return localVariableTables.get(this); + } } Modified: rvmroot/trunk/rvm/src/org/jikesrvm/classloader/RVMMethod.java =================================================================== --- rvmroot/trunk/rvm/src/org/jikesrvm/classloader/RVMMethod.java 2009-01-01 23:41:31 UTC (rev 15247) +++ rvmroot/trunk/rvm/src/org/jikesrvm/classloader/RVMMethod.java 2009-01-02 00:18:20 UTC (rev 15248) @@ -149,6 +149,7 @@ ExceptionHandlerMap tmp_exceptionHandlerMap = null; TypeReference[] tmp_exceptionTypes = null; int[] tmp_lineNumberMap = null; + LocalVariableTable tmp_localVariableTable = null; Atom tmp_signature = null; RVMAnnotation[] annotations = null; RVMAnnotation[][] parameterAnnotations = null; @@ -182,6 +183,8 @@ tmp_lineNumberMap[k] = (lineNumber << BITS_IN_SHORT) | startPC; } } + } else if (attName == RVMClassLoader.localVariableTableAttributeName) { + tmp_localVariableTable = LocalVariableTable.readLocalVariableTable(input, constantPool); } else { // All other entries in the attribute portion of the code attribute are boring. int skippedAmount = input.skipBytes(attLength); @@ -257,6 +260,7 @@ tmp_bytecodes, tmp_exceptionHandlerMap, tmp_lineNumberMap, + tmp_localVariableTable, constantPool, tmp_signature, annotations, @@ -298,6 +302,7 @@ bytecodes, null, null, + null, constantPool, null, null, @@ -354,6 +359,7 @@ bytecode, null, null, + null, constantPool, null, null, @@ -901,6 +907,7 @@ new byte[]{(byte)JBC_return}, null, null, + null, new int[0], null, null, @@ -1071,6 +1078,7 @@ bytecodes, null, null, + null, constantPool, null, null, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |