diff --git a/rxlib/src/main/java/org/rx/core/Reflects.java b/rxlib/src/main/java/org/rx/core/Reflects.java index 3f16bfeb..aab429a9 100644 --- a/rxlib/src/main/java/org/rx/core/Reflects.java +++ b/rxlib/src/main/java/org/rx/core/Reflects.java @@ -58,11 +58,21 @@ static class ConvertBean { final TripleFunc, TT> converter; } - static class SecurityManagerEx extends SecurityManager { + public interface ClassTracer { + Class[] getClassTrace(); + + Class getClassTrace(int depth); + } + + static class SecurityManagerEx extends SecurityManager implements ClassTracer { static final SecurityManagerEx INSTANCE = new SecurityManagerEx(); - Class stackClass(int depth) { - return getClassContext()[depth]; + public Class[] getClassTrace() { + return getClassContext(); + } + + public Class getClassTrace(int depth) { + return getClassContext()[1 + depth]; } } //endregion @@ -70,6 +80,7 @@ Class stackClass(int depth) { public static final Linq COLLECTION_WRITE_METHOD_NAMES = Linq.from("add", "remove", "addAll", "removeAll", "removeIf", "retainAll", "clear"), List_WRITE_METHOD_NAMES = COLLECTION_WRITE_METHOD_NAMES.union(Arrays.toList("replaceAll", "set")); public static final Set OBJECT_METHODS = Collections.unmodifiableSet(new HashSet<>(Arrays.toList(Object.class.getMethods()))); + public static final ClassTracer CLASS_TRACER = new SecurityManagerEx(); static final String M_0 = "close", CHANGE_TYPE_METHOD = "valueOf"; static final String GET_PROPERTY = "get", GET_BOOL_PROPERTY = "is", SET_PROPERTY = "set"; static final String TYPED_JSON_KEY = "$rxType"; @@ -123,7 +134,7 @@ public static Class getCallerClass() { public static Class stackClass(int depth) { //Throwable.class.getDeclaredMethod("getStackTraceElement", int.class) & Reflection.getCallerClass(2 + depth) java 11 not exist - return SecurityManagerEx.INSTANCE.stackClass(2 + depth); + return SecurityManagerEx.INSTANCE.getClassTrace()[2 + depth]; } public static InputStream getResource(String namePattern) { diff --git a/rxlib/src/main/java/org/rx/core/ThreadPool.java b/rxlib/src/main/java/org/rx/core/ThreadPool.java index e17a81ec..6fb7594b 100644 --- a/rxlib/src/main/java/org/rx/core/ThreadPool.java +++ b/rxlib/src/main/java/org/rx/core/ThreadPool.java @@ -179,7 +179,7 @@ private Task(Func fn, FlagsEnum flags, Object id) { } if (conf.trace.slowMethodElapsedMicros > 0) { //Reflects.getStackTrace(t) - caller = Reflects.getCallerClass(); + caller = Reflects.CLASS_TRACER.getClassTrace(0); } else { caller = null; } @@ -205,7 +205,7 @@ public T call() { throw e; } finally { Thread t = Thread.currentThread(); - TraceHandler.INSTANCE.saveMethodTrace(t, ifNull(caller, ThreadPool.class), fn.getClass().getName(), id == null ? null : new Object[]{id}, + TraceHandler.INSTANCE.saveMethodTrace(t, ifNull(caller, ThreadPool.class), fn.getClass().getSimpleName(), id == null ? null : new Object[]{id}, r, ex, System.nanoTime() - s); } return r; diff --git a/rxlib/src/test/java/org/rx/core/TestCore.java b/rxlib/src/test/java/org/rx/core/TestCore.java index e15cacf1..3f9de77b 100644 --- a/rxlib/src/test/java/org/rx/core/TestCore.java +++ b/rxlib/src/test/java/org/rx/core/TestCore.java @@ -999,7 +999,8 @@ public void reflect() { System.out.println(resource); assert resource != null; } - assert Reflects.stackClass(0) == this.getClass(); + System.out.println(toJsonString(Reflects.CLASS_TRACER.getClassTrace())); + assert Reflects.CLASS_TRACER.getClassTrace(0) == this.getClass(); // for (StackTraceElement traceElement : Reflects.stackTrace(8)) { // System.out.println(traceElement); // }