--- old/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java 2012-06-19 17:55:55.708771839 -0700 +++ new/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java 2012-06-19 17:55:55.640771898 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -47,15 +47,12 @@ private static int HAS_LINENUMBER_TABLE; private static int HAS_CHECKED_EXCEPTIONS; private static int HAS_LOCALVARIABLE_TABLE; + private static int HAS_EXCEPTION_TABLE; private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { Type type = db.lookupType("constMethodOopDesc"); // Backpointer to non-const methodOop method = new OopField(type.getOopField("_method"), 0); - // The exception handler table. 4-tuples of ints [start_pc, end_pc, - // handler_pc, catch_type index] For methods with no exceptions the - // table is pointing to Universe::the_empty_int_array - exceptionTable = new OopField(type.getOopField("_exception_table"), 0); constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0); flags = new ByteField(type.getJByteField("_flags"), 0); @@ -63,6 +60,7 @@ HAS_LINENUMBER_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_linenumber_table").intValue(); HAS_CHECKED_EXCEPTIONS = db.lookupIntConstant("constMethodOopDesc::_has_checked_exceptions").intValue(); HAS_LOCALVARIABLE_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_localvariable_table").intValue(); + HAS_EXCEPTION_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_exception_table").intValue(); // Size of Java bytecodes allocated immediately after constMethodOop. codeSize = new CIntField(type.getCIntegerField("_code_size"), 0); @@ -78,6 +76,9 @@ type = db.lookupType("LocalVariableTableElement"); localVariableTableElementSize = type.getSize(); + + type = db.lookupType("ExceptionTableElement"); + exceptionTableElementSize = type.getSize(); } ConstMethod(OopHandle handle, ObjectHeap heap) { @@ -86,7 +87,6 @@ // Fields private static OopField method; - private static OopField exceptionTable; private static CIntField constMethodSize; private static ByteField flags; private static CIntField codeSize; @@ -99,16 +99,13 @@ private static long checkedExceptionElementSize; private static long localVariableTableElementSize; + private static long exceptionTableElementSize; // Accessors for declared fields public Method getMethod() { return (Method) method.getValue(this); } - public TypeArray getExceptionTable() { - return (TypeArray) exceptionTable.getValue(this); - } - public long getConstMethodSize() { return constMethodSize.getValue(this); } @@ -224,7 +221,6 @@ super.iterateFields(visitor, doVMFields); if (doVMFields) { visitor.doOop(method, true); - visitor.doOop(exceptionTable, true); visitor.doCInt(constMethodSize, true); visitor.doByte(flags, true); visitor.doCInt(codeSize, true); @@ -315,6 +311,23 @@ return ret; } + public boolean hasExceptionTable() { + return (getFlags() & HAS_EXCEPTION_TABLE) != 0; + } + + public ExceptionTableElement[] getExceptionTable() { + if (Assert.ASSERTS_ENABLED) { + Assert.that(hasExceptionTable(), "should only be called if table is present"); + } + ExceptionTableElement[] ret = new ExceptionTableElement[getExceptionTableLength()]; + long offset = offsetOfExceptionTable(); + for (int i = 0; i < ret.length; i++) { + ret[i] = new ExceptionTableElement(getHandle(), offset); + offset += exceptionTableElementSize; + } + return ret; + } + public boolean hasCheckedExceptions() { return (getFlags() & HAS_CHECKED_EXCEPTIONS) != 0; } @@ -404,7 +417,10 @@ if (Assert.ASSERTS_ENABLED) { Assert.that(hasLocalVariableTable(), "should only be called if table is present"); } - if (hasCheckedExceptions()) { + + if (hasExceptionTable()) { + return offsetOfExceptionTable() - 2; + } else if (hasCheckedExceptions()) { return offsetOfCheckedExceptions() - 2; } else { return offsetOfLastU2Element(); @@ -421,4 +437,33 @@ return offset; } + private int getExceptionTableLength() { + if (hasExceptionTable()) { + return (int) getHandle().getCIntegerAt(offsetOfExceptionTableLength(), 2, true); + } else { + return 0; + } + } + + private long offsetOfExceptionTableLength() { + if (Assert.ASSERTS_ENABLED) { + Assert.that(hasExceptionTable(), "should only be called if table is present"); + } + if (hasCheckedExceptions()) { + return offsetOfCheckedExceptions() - 2; + } else { + return offsetOfLastU2Element(); + } + } + + private long offsetOfExceptionTable() { + long offset = offsetOfExceptionTableLength(); + long length = getExceptionTableLength(); + if (Assert.ASSERTS_ENABLED) { + Assert.that(length > 0, "should only be called if table is present"); + } + offset -= length * exceptionTableElementSize; + return offset; + } + }