# HG changeset patch # User Matthias Grimmer # Date 1360758845 -3600 # Node ID 8bbbde9d0a52e280492a375327264bfb80a43ae0 # Parent f180d2a1c3a476ddfc9143a153033c5d46a79db7 extended ResolvedJavaMethod API by getLocalVariableTable diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Local.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Local.java Wed Feb 13 13:34:05 2013 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011, 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. + * + * 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 com.oracle.graal.api.meta; + +public interface Local { + + int getStartBCI(); + + int getEndBCI(); + + int getSlot(); + + String getName(); + + ResolvedJavaType getType(); +} diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocalVariableTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocalVariableTable.java Wed Feb 13 13:34:05 2013 +0100 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2011, 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. + * + * 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 com.oracle.graal.api.meta; + +public interface LocalVariableTable { + + Local[] getLocals(); + + Local[] getLocalsAt(int bci); + + Local getLocal(int slot, int bci); +} diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Wed Feb 13 11:37:14 2013 +1000 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Wed Feb 13 13:34:05 2013 +0100 @@ -170,4 +170,10 @@ * Returns the LineNumberTable of this method. */ LineNumberTable getLineNumberTable(); + + /** + * Returns the localvariable table of this method. + */ + LocalVariableTable getLocalVariableTable(); + } diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed Feb 13 11:37:14 2013 +1000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed Feb 13 13:34:05 2013 +0100 @@ -207,5 +207,7 @@ long[] getLineNumberTable(HotSpotResolvedJavaMethod method); + Local[] getLocalVariableTable(HotSpotResolvedJavaMethod method); + String getFileName(HotSpotResolvedJavaType method); } diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Wed Feb 13 11:37:14 2013 +1000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Wed Feb 13 13:34:05 2013 +0100 @@ -150,5 +150,8 @@ public native long[] getLineNumberTable(HotSpotResolvedJavaMethod method); @Override + public native Local[] getLocalVariableTable(HotSpotResolvedJavaMethod method); + + @Override public native String getFileName(HotSpotResolvedJavaType method); } diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java Wed Feb 13 11:37:14 2013 +1000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java Wed Feb 13 13:34:05 2013 +0100 @@ -26,6 +26,7 @@ import java.io.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.debug.*; import com.oracle.graal.hotspot.meta.*; /** @@ -77,4 +78,6 @@ Constant createConstantDouble(double value); Constant createConstantObject(Object object); + + LocalImpl createLocalImpl(String name, String type, HotSpotResolvedObjectType holder, int bciStart, int bciEnd, int slot); } diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Feb 13 11:37:14 2013 +1000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Feb 13 13:34:05 2013 +0100 @@ -40,6 +40,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.debug.internal.*; import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.debug.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.phases.*; import com.oracle.graal.java.*; @@ -608,6 +609,11 @@ return Constant.forObject(object); } + @Override + public LocalImpl createLocalImpl(String name, String type, HotSpotResolvedObjectType holder, int bciStart, int bciEnd, int slot) { + return new LocalImpl(name, type, holder, bciStart, bciEnd, slot); + } + public PhasePlan createPhasePlan(OptimisticOptimizations optimisticOpts, boolean onStackReplacement) { PhasePlan phasePlan = new PhasePlan(); phasePlan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(graalRuntime.getRuntime(), GraphBuilderConfiguration.getDefault(), optimisticOpts)); diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/LocalImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/LocalImpl.java Wed Feb 13 13:34:05 2013 +0100 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2011, 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. + * + * 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 com.oracle.graal.hotspot.debug; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.meta.*; + +public class LocalImpl implements Local { + + private final String name; + private final int bciStart; + private final int bciEnd; + private final int slot; + private final ResolvedJavaType resolvedType; + + public LocalImpl(String name, String type, HotSpotResolvedObjectType holder, int bciStart, int bciEnd, int slot) { + this.name = name; + this.bciStart = bciStart; + this.bciEnd = bciEnd; + this.slot = slot; + JavaType t = HotSpotGraalRuntime.getInstance().lookupType(type, holder, true); + if (t instanceof ResolvedJavaType) { + this.resolvedType = (ResolvedJavaType) HotSpotGraalRuntime.getInstance().lookupType(type, holder, false); + } else { + throw new AssertionError(t.getClass() + " is not a ResolvedJavaType"); + } + } + + @Override + public int getStartBCI() { + return bciStart; + } + + @Override + public int getEndBCI() { + return bciEnd; + } + + @Override + public String getName() { + return name; + } + + @Override + public ResolvedJavaType getType() { + return resolvedType; + } + + @Override + public int getSlot() { + return slot; + } +} diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/LocalVariableTableImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/LocalVariableTableImpl.java Wed Feb 13 13:34:05 2013 +0100 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2011, 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. + * + * 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 com.oracle.graal.hotspot.debug; + +import java.util.*; + +import com.oracle.graal.api.meta.*; + +public class LocalVariableTableImpl implements LocalVariableTable { + + private final Local[] locals; + + public LocalVariableTableImpl(Local[] locals) { + this.locals = locals; + } + + @Override + public Local getLocal(int slot, int bci) { + Local result = null; + for (Local local : locals) { + if (local.getSlot() == slot && local.getStartBCI() <= bci && local.getEndBCI() >= bci) { + if (result == null) { + result = local; + } else { + throw new IllegalStateException("Locals overlap!"); + } + } + } + return result; + } + + @Override + public Local[] getLocals() { + return locals; + } + + @Override + public Local[] getLocalsAt(int bci) { + List result = new ArrayList<>(); + for (Local l : locals) { + if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) { + result.add(l); + } + } + return result.toArray(new Local[result.size()]); + } + +} diff -r f180d2a1c3a4 -r 8bbbde9d0a52 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Wed Feb 13 11:37:14 2013 +1000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Wed Feb 13 13:34:05 2013 +0100 @@ -308,6 +308,12 @@ return new LineNumberTableImpl(line, bci); } + @Override + public LocalVariableTable getLocalVariableTable() { + Local[] locals = HotSpotGraalRuntime.getInstance().getCompilerToVM().getLocalVariableTable(this); + return new LocalVariableTableImpl(locals); + } + /** * Returns the offset of this method into the v-table. If the holder is not initialized, returns * -1 diff -r f180d2a1c3a4 -r 8bbbde9d0a52 src/share/vm/classfile/systemDictionary.hpp --- a/src/share/vm/classfile/systemDictionary.hpp Wed Feb 13 11:37:14 2013 +1000 +++ b/src/share/vm/classfile/systemDictionary.hpp Wed Feb 13 13:34:05 2013 +0100 @@ -193,6 +193,7 @@ do_klass(HotSpotResolvedJavaField_klass, com_oracle_graal_hotspot_meta_HotSpotResolvedJavaField, Opt) \ do_klass(HotSpotResolvedJavaMethod_klass, com_oracle_graal_hotspot_meta_HotSpotResolvedJavaMethod, Opt) \ do_klass(HotSpotResolvedObjectType_klass, com_oracle_graal_hotspot_meta_HotSpotResolvedObjectType, Opt) \ + do_klass(LocalImpl_klass, com_oracle_graal_hotspot_debug_LocalImpl, Opt) \ /* graal.api.code */ \ do_klass(Assumptions_klass, com_oracle_graal_api_code_Assumptions, Opt) \ do_klass(Assumptions_ConcreteMethod_klass, com_oracle_graal_api_code_Assumptions_ConcreteMethod, Opt) \ diff -r f180d2a1c3a4 -r 8bbbde9d0a52 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Wed Feb 13 11:37:14 2013 +1000 +++ b/src/share/vm/classfile/vmSymbols.hpp Wed Feb 13 13:34:05 2013 +0100 @@ -303,6 +303,7 @@ template(com_oracle_graal_hotspot_meta_HotSpotResolvedJavaField, "com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField") \ template(com_oracle_graal_hotspot_meta_HotSpotResolvedJavaMethod, "com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod") \ template(com_oracle_graal_hotspot_meta_HotSpotResolvedObjectType, "com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType") \ + template(com_oracle_graal_hotspot_debug_LocalImpl, "com/oracle/graal/hotspot/debug/LocalImpl") \ AMD64_ONLY(template(com_oracle_graal_hotspot_amd64_AMD64HotSpotGraalRuntime,"com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime"))\ /* graal.api.meta */ \ template(com_oracle_graal_api_meta_Constant, "com/oracle/graal/api/meta/Constant") \ @@ -354,6 +355,8 @@ template(createResolvedJavaType_signature, "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/Class;ZI)Lcom/oracle/graal/api/meta/ResolvedJavaType;") \ template(createPrimitiveJavaType_name, "createPrimitiveJavaType") \ template(createPrimitiveJavaType_signature, "(I)Lcom/oracle/graal/api/meta/JavaType;") \ + template(createLocalImpl_name, "createLocalImpl") \ + template(createLocalImpl_signature, "(Ljava/lang/String;Ljava/lang/String;Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;III)Lcom/oracle/graal/hotspot/debug/LocalImpl;") \ template(createConstant_name, "createConstant") \ template(createConstant_signature, "(Lcom/oracle/graal/api/meta/Kind;J)Lcom/oracle/graal/api/meta/Constant;") \ template(createConstantFloat_name, "createConstantFloat") \ diff -r f180d2a1c3a4 -r 8bbbde9d0a52 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Wed Feb 13 11:37:14 2013 +1000 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Wed Feb 13 13:34:05 2013 +0100 @@ -992,6 +992,38 @@ return result; C2V_END +C2V_VMENTRY(jobject, getLocalVariableTable, (JNIEnv *, jobject, jobject hotspot_method)) + ResourceMark rm; + + Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); + if(!method->has_localvariable_table()) { + return NULL; + } + int localvariable_table_length = method->localvariable_table_length(); + + objArrayHandle local_array = oopFactory::new_objArray(SystemDictionary::LocalImpl_klass(), localvariable_table_length, CHECK_NULL); + LocalVariableTableElement* table = method->localvariable_table_start(); + for (int i = 0; i < localvariable_table_length; i++) { + u2 start_bci = table[i].start_bci; + u4 end_bci = (u4)(start_bci + table[i].length); + u2 nameCPIdx = table[i].name_cp_index; + u2 typeCPIdx = table[i].descriptor_cp_index; + u2 slot = table[i].slot; + + char* name = method->constants()->string_at_noresolve(nameCPIdx); + Handle nameHandle = java_lang_String::create_from_str(name, CHECK_NULL); + + char* typeInfo = method->constants()->string_at_noresolve(typeCPIdx); + Handle typeHandle = java_lang_String::create_from_str(typeInfo, CHECK_NULL); + + Handle holderHandle = GraalCompiler::createHotSpotResolvedObjectType(method, CHECK_0); + Handle local = VMToCompiler::createLocal(nameHandle, typeHandle, (int) start_bci, (int) end_bci, (int) slot, holderHandle, Thread::current()); + local_array->obj_at_put(i, local()); + } + + return JNIHandles::make_local(local_array()); +C2V_END + C2V_VMENTRY(jobject, getFileName, (JNIEnv *, jobject, jobject klass)) ResourceMark rm; @@ -1016,6 +1048,7 @@ #define CONSTANT_POOL "Lcom/oracle/graal/api/meta/ConstantPool;" #define CONSTANT "Lcom/oracle/graal/api/meta/Constant;" #define KIND "Lcom/oracle/graal/api/meta/Kind;" +#define LOCAL "Lcom/oracle/graal/api/meta/Local;" #define RUNTIME_CALL "Lcom/oracle/graal/api/code/RuntimeCall;" #define EXCEPTION_HANDLERS "[Lcom/oracle/graal/api/meta/ExceptionHandler;" #define REFLECT_METHOD "Ljava/lang/reflect/Method;" @@ -1077,6 +1110,7 @@ {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, {CC"decodePC", CC"(J)"STRING, FN_PTR(decodePC)}, {CC"getLineNumberTable", CC"("HS_RESOLVED_METHOD")[J", FN_PTR(getLineNumberTable)}, + {CC"getLocalVariableTable", CC"("HS_RESOLVED_METHOD")["LOCAL, FN_PTR(getLocalVariableTable)}, {CC"getFileName", CC"("HS_RESOLVED_JAVA_TYPE")"STRING, FN_PTR(getFileName)}, }; diff -r f180d2a1c3a4 -r 8bbbde9d0a52 src/share/vm/graal/graalVMToCompiler.cpp --- a/src/share/vm/graal/graalVMToCompiler.cpp Wed Feb 13 11:37:14 2013 +1000 +++ b/src/share/vm/graal/graalVMToCompiler.cpp Wed Feb 13 13:34:05 2013 +0100 @@ -267,3 +267,19 @@ return (oop) result.get_jobject(); } +oop VMToCompiler::createLocal(Handle name, Handle typeInfo, int bci_start, int bci_end, int slot, Handle holder, TRAPS) { + JavaValue result(T_OBJECT); + JavaCallArguments args; + args.push_oop(instance()); + args.push_oop(name); + args.push_oop(typeInfo); + args.push_oop(holder); + args.push_int(bci_start); + args.push_int(bci_end); + args.push_int(slot); + JavaCalls::call_interface(&result, vmToCompilerKlass(), vmSymbols::createLocalImpl_name(), vmSymbols::createLocalImpl_signature(), &args, THREAD); + check_pending_exception("Error while calling createConstantFloat"); + return (oop) result.get_jobject(); + +} + diff -r f180d2a1c3a4 -r 8bbbde9d0a52 src/share/vm/graal/graalVMToCompiler.hpp --- a/src/share/vm/graal/graalVMToCompiler.hpp Wed Feb 13 11:37:14 2013 +1000 +++ b/src/share/vm/graal/graalVMToCompiler.hpp Wed Feb 13 13:34:05 2013 +0100 @@ -94,6 +94,9 @@ // public abstract Constant createConstantObject(long vmId); static oop createConstantObject(Handle object, TRAPS); + + // public abstract Local createLocal(String name, int bci_start, int bci_end); + static oop createLocal(Handle name, Handle type, int bci_start, int bci_end, int slot, Handle holder, TRAPS); }; inline void check_pending_exception(const char* message, bool dump_core = false) {