diff options
Diffstat (limited to 'test/1915-get-set-local-current-thread/src')
| -rw-r--r-- | test/1915-get-set-local-current-thread/src/Main.java | 6 | ||||
| -rw-r--r-- | test/1915-get-set-local-current-thread/src/art/Test1915.java | 124 |
2 files changed, 65 insertions, 65 deletions
diff --git a/test/1915-get-set-local-current-thread/src/Main.java b/test/1915-get-set-local-current-thread/src/Main.java index 47e676704f..5ca6f0964e 100644 --- a/test/1915-get-set-local-current-thread/src/Main.java +++ b/test/1915-get-set-local-current-thread/src/Main.java @@ -15,7 +15,7 @@ */ public class Main { - public static void main(String[] args) throws Exception { - art.Test1915.run(); - } + public static void main(String[] args) throws Exception { + art.Test1915.run(); + } } diff --git a/test/1915-get-set-local-current-thread/src/art/Test1915.java b/test/1915-get-set-local-current-thread/src/art/Test1915.java index a99a487ea6..8398afa254 100644 --- a/test/1915-get-set-local-current-thread/src/art/Test1915.java +++ b/test/1915-get-set-local-current-thread/src/art/Test1915.java @@ -31,75 +31,75 @@ import java.util.function.Supplier; import java.util.function.Consumer; public class Test1915 { - public static final int SET_VALUE = 1337; - public static final String TARGET_VAR = "TARGET"; + public static final int SET_VALUE = 1337; + public static final String TARGET_VAR = "TARGET"; - public static void reportValue(Object val) { - System.out.println("\tValue is '" + val + "'"); - } - public static interface ThrowRunnable { - public void run() throws Exception; - } + public static void reportValue(Object val) { + System.out.println("\tValue is '" + val + "'"); + } + public static interface ThrowRunnable { + public void run() throws Exception; + } - public static void IntMethod(ThrowRunnable safepoint) throws Exception { - int TARGET = 42; - safepoint.run(); - reportValue(TARGET); - } + public static void IntMethod(ThrowRunnable safepoint) throws Exception { + int TARGET = 42; + safepoint.run(); + reportValue(TARGET); + } - public static void run() throws Exception { - Locals.EnableLocalVariableAccess(); - final Method target = Test1915.class.getDeclaredMethod("IntMethod", ThrowRunnable.class); - // Get Variable. - System.out.println("GetLocalInt on current thread!"); - IntMethod(() -> { - StackTrace.StackFrameData frame = FindStackFrame(target); - int depth = FindExpectedFrameDepth(frame); - int slot = FindSlot(frame); - int value = Locals.GetLocalVariableInt(Thread.currentThread(), depth, slot); - System.out.println("From GetLocalInt(), value is " + value); - }); - // Set Variable. - System.out.println("SetLocalInt on current thread!"); - IntMethod(() -> { - StackTrace.StackFrameData frame = FindStackFrame(target); - int depth = FindExpectedFrameDepth(frame); - int slot = FindSlot(frame); - Locals.SetLocalVariableInt(Thread.currentThread(), depth, slot, SET_VALUE); - }); - } + public static void run() throws Exception { + Locals.EnableLocalVariableAccess(); + final Method target = Test1915.class.getDeclaredMethod("IntMethod", ThrowRunnable.class); + // Get Variable. + System.out.println("GetLocalInt on current thread!"); + IntMethod(() -> { + StackTrace.StackFrameData frame = FindStackFrame(target); + int depth = FindExpectedFrameDepth(frame); + int slot = FindSlot(frame); + int value = Locals.GetLocalVariableInt(Thread.currentThread(), depth, slot); + System.out.println("From GetLocalInt(), value is " + value); + }); + // Set Variable. + System.out.println("SetLocalInt on current thread!"); + IntMethod(() -> { + StackTrace.StackFrameData frame = FindStackFrame(target); + int depth = FindExpectedFrameDepth(frame); + int slot = FindSlot(frame); + Locals.SetLocalVariableInt(Thread.currentThread(), depth, slot, SET_VALUE); + }); + } - public static int FindSlot(StackTrace.StackFrameData frame) throws Exception { - long loc = frame.current_location; - for (Locals.VariableDescription var : Locals.GetLocalVariableTable(frame.method)) { - if (var.start_location <= loc && - var.length + var.start_location > loc && - var.name.equals(TARGET_VAR)) { - return var.slot; - } + public static int FindSlot(StackTrace.StackFrameData frame) throws Exception { + long loc = frame.current_location; + for (Locals.VariableDescription var : Locals.GetLocalVariableTable(frame.method)) { + if (var.start_location <= loc && + var.length + var.start_location > loc && + var.name.equals(TARGET_VAR)) { + return var.slot; + } + } + throw new Error( + "Unable to find variable " + TARGET_VAR + " in " + frame.method + " at loc " + loc); } - throw new Error( - "Unable to find variable " + TARGET_VAR + " in " + frame.method + " at loc " + loc); - } - public static int FindExpectedFrameDepth(StackTrace.StackFrameData frame) throws Exception { - // Adjust the 'frame' depth since it is modified by: - // +1 for Get/SetLocalVariableInt in future. - // -1 for FindStackFrame - // -1 for GetStackTrace - // -1 for GetStackTraceNative - // ------------------------------ - // -2 - return frame.depth - 2; - } + public static int FindExpectedFrameDepth(StackTrace.StackFrameData frame) throws Exception { + // Adjust the 'frame' depth since it is modified by: + // +1 for Get/SetLocalVariableInt in future. + // -1 for FindStackFrame + // -1 for GetStackTrace + // -1 for GetStackTraceNative + // ------------------------------ + // -2 + return frame.depth - 2; + } - private static StackTrace.StackFrameData FindStackFrame(Method target) { - for (StackTrace.StackFrameData frame : StackTrace.GetStackTrace(Thread.currentThread())) { - if (frame.method.equals(target)) { - return frame; - } + private static StackTrace.StackFrameData FindStackFrame(Method target) { + for (StackTrace.StackFrameData frame : StackTrace.GetStackTrace(Thread.currentThread())) { + if (frame.method.equals(target)) { + return frame; + } + } + throw new Error("Unable to find stack frame in method " + target); } - throw new Error("Unable to find stack frame in method " + target); - } } |