提交 84521fd4 编写于 作者: L lbourges

8144654: Improve Marlin logging

Reviewed-by: prr, flar
上级 bbb70c58
...@@ -74,7 +74,7 @@ final class ByteArrayCache implements MarlinConst { ...@@ -74,7 +74,7 @@ final class ByteArrayCache implements MarlinConst {
void putDirtyArray(final byte[] array, final int length) { void putDirtyArray(final byte[] array, final int length) {
if (length != arraySize) { if (length != arraySize) {
if (doChecks) { if (doChecks) {
System.out.println("ArrayCache: bad length = " + length); MarlinUtils.logInfo("ArrayCache: bad length = " + length);
} }
return; return;
} }
...@@ -98,7 +98,7 @@ final class ByteArrayCache implements MarlinConst { ...@@ -98,7 +98,7 @@ final class ByteArrayCache implements MarlinConst {
{ {
if (length != arraySize) { if (length != arraySize) {
if (doChecks) { if (doChecks) {
System.out.println("ArrayCache: bad length = " + length); MarlinUtils.logInfo("ArrayCache: bad length = " + length);
} }
return; return;
} }
......
...@@ -75,7 +75,7 @@ final class FloatArrayCache implements MarlinConst { ...@@ -75,7 +75,7 @@ final class FloatArrayCache implements MarlinConst {
void putDirtyArray(final float[] array, final int length) { void putDirtyArray(final float[] array, final int length) {
if (length != arraySize) { if (length != arraySize) {
if (doChecks) { if (doChecks) {
System.out.println("ArrayCache: bad length = " + length); MarlinUtils.logInfo("ArrayCache: bad length = " + length);
} }
return; return;
} }
...@@ -99,7 +99,7 @@ final class FloatArrayCache implements MarlinConst { ...@@ -99,7 +99,7 @@ final class FloatArrayCache implements MarlinConst {
{ {
if (length != arraySize) { if (length != arraySize) {
if (doChecks) { if (doChecks) {
System.out.println("ArrayCache: bad length = " + length); MarlinUtils.logInfo("ArrayCache: bad length = " + length);
} }
return; return;
} }
......
...@@ -74,7 +74,7 @@ final class IntArrayCache implements MarlinConst { ...@@ -74,7 +74,7 @@ final class IntArrayCache implements MarlinConst {
void putDirtyArray(final int[] array, final int length) { void putDirtyArray(final int[] array, final int length) {
if (length != arraySize) { if (length != arraySize) {
if (doChecks) { if (doChecks) {
System.out.println("ArrayCache: bad length = " + length); MarlinUtils.logInfo("ArrayCache: bad length = " + length);
} }
return; return;
} }
...@@ -98,7 +98,7 @@ final class IntArrayCache implements MarlinConst { ...@@ -98,7 +98,7 @@ final class IntArrayCache implements MarlinConst {
{ {
if (length != arraySize) { if (length != arraySize) {
if (doChecks) { if (doChecks) {
System.out.println("ArrayCache: bad length = " + length); MarlinUtils.logInfo("ArrayCache: bad length = " + length);
} }
return; return;
} }
......
...@@ -30,8 +30,8 @@ package sun.java2d.marlin; ...@@ -30,8 +30,8 @@ package sun.java2d.marlin;
*/ */
interface MarlinConst { interface MarlinConst {
// enable Logs (logger or stdout) // enable Logs (logger or stdout)
static final boolean enableLogs = false; static final boolean enableLogs = MarlinProperties.isLoggingEnabled();
// enable Logger // use Logger instead of stdout
static final boolean useLogger = enableLogs && MarlinProperties.isUseLogger(); static final boolean useLogger = enableLogs && MarlinProperties.isUseLogger();
// log new RendererContext // log new RendererContext
...@@ -47,9 +47,10 @@ interface MarlinConst { ...@@ -47,9 +47,10 @@ interface MarlinConst {
static final boolean doStats = enableLogs && MarlinProperties.isDoStats(); static final boolean doStats = enableLogs && MarlinProperties.isDoStats();
// do monitors // do monitors
// disabled to reduce byte-code size a bit... // disabled to reduce byte-code size a bit...
static final boolean doMonitors = enableLogs && false; // MarlinProperties.isDoMonitors(); static final boolean doMonitors = false;
// static final boolean doMonitors = enableLogs && MarlinProperties.isDoMonitors();
// do checks // do checks
static final boolean doChecks = false; // MarlinProperties.isDoChecks(); static final boolean doChecks = enableLogs && MarlinProperties.isDoChecks();
// do AA range checks: disable when algorithm / code is stable // do AA range checks: disable when algorithm / code is stable
static final boolean DO_AA_RANGE_CHECK = false; static final boolean DO_AA_RANGE_CHECK = false;
......
...@@ -136,6 +136,10 @@ public final class MarlinProperties { ...@@ -136,6 +136,10 @@ public final class MarlinProperties {
// logging parameters // logging parameters
public static boolean isLoggingEnabled() {
return getBoolean("sun.java2d.renderer.log", "false");
}
public static boolean isUseLogger() { public static boolean isUseLogger() {
return getBoolean("sun.java2d.renderer.useLogger", "false"); return getBoolean("sun.java2d.renderer.useLogger", "false");
} }
......
...@@ -27,12 +27,12 @@ package sun.java2d.marlin; ...@@ -27,12 +27,12 @@ package sun.java2d.marlin;
public final class MarlinUtils { public final class MarlinUtils {
// TODO: use sun.util.logging.PlatformLogger once in JDK9 // Marlin logger
private static final java.util.logging.Logger log; private static final sun.util.logging.PlatformLogger log;
static { static {
if (MarlinConst.useLogger) { if (MarlinConst.useLogger) {
log = java.util.logging.Logger.getLogger("sun.java2d.marlin"); log = sun.util.logging.PlatformLogger.getLogger("sun.java2d.marlin");
} else { } else {
log = null; log = null;
} }
...@@ -53,25 +53,11 @@ public final class MarlinUtils { ...@@ -53,25 +53,11 @@ public final class MarlinUtils {
public static void logException(final String msg, final Throwable th) { public static void logException(final String msg, final Throwable th) {
if (MarlinConst.useLogger) { if (MarlinConst.useLogger) {
// log.warning(msg, th); log.warning(msg, th);
log.log(java.util.logging.Level.WARNING, msg, th);
} else if (MarlinConst.enableLogs) { } else if (MarlinConst.enableLogs) {
System.out.print("WARNING: "); System.out.print("WARNING: ");
System.out.println(msg); System.out.println(msg);
th.printStackTrace(System.err); th.printStackTrace(System.err);
} }
} }
// Returns the caller's class and method's name; best effort
// if cannot infer, return the logger's name.
static String getCallerInfo(String className) {
String sourceClassName = null;
String sourceMethodName = null;
if (sourceClassName != null) {
return sourceClassName + " " + sourceMethodName;
} else {
return "unknown";
}
}
} }
...@@ -31,7 +31,6 @@ import java.lang.ref.WeakReference; ...@@ -31,7 +31,6 @@ import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static sun.java2d.marlin.ArrayCache.*; import static sun.java2d.marlin.ArrayCache.*;
import sun.java2d.marlin.MarlinRenderingEngine.NormalizingPathIterator; import sun.java2d.marlin.MarlinRenderingEngine.NormalizingPathIterator;
import static sun.java2d.marlin.MarlinUtils.getCallerInfo;
import static sun.java2d.marlin.MarlinUtils.logInfo; import static sun.java2d.marlin.MarlinUtils.logInfo;
/** /**
...@@ -39,7 +38,6 @@ import static sun.java2d.marlin.MarlinUtils.logInfo; ...@@ -39,7 +38,6 @@ import static sun.java2d.marlin.MarlinUtils.logInfo;
*/ */
final class RendererContext implements MarlinConst { final class RendererContext implements MarlinConst {
private static final String className = RendererContext.class.getName();
// RendererContext creation counter // RendererContext creation counter
private static final AtomicInteger contextCount = new AtomicInteger(1); private static final AtomicInteger contextCount = new AtomicInteger(1);
// RendererContext statistics // RendererContext statistics
...@@ -214,8 +212,7 @@ final class RendererContext implements MarlinConst { ...@@ -214,8 +212,7 @@ final class RendererContext implements MarlinConst {
} }
if (doLogOverSize) { if (doLogOverSize) {
logInfo("getDirtyByteArray[oversize]: length=\t" + length logInfo("getDirtyByteArray[oversize]: length=\t" + length);
+ "\tfrom=\t" + getCallerInfo(className));
} }
return new byte[length]; return new byte[length];
...@@ -254,7 +251,7 @@ final class RendererContext implements MarlinConst { ...@@ -254,7 +251,7 @@ final class RendererContext implements MarlinConst {
if (doLogWidenArray) { if (doLogWidenArray) {
logInfo("widenDirtyByteArray[" + res.length + "]: usedSize=\t" logInfo("widenDirtyByteArray[" + res.length + "]: usedSize=\t"
+ usedSize + "\tlength=\t" + length + "\tneeded length=\t" + usedSize + "\tlength=\t" + length + "\tneeded length=\t"
+ needSize + "\tfrom=\t" + getCallerInfo(className)); + needSize);
} }
return res; return res;
} }
...@@ -275,8 +272,7 @@ final class RendererContext implements MarlinConst { ...@@ -275,8 +272,7 @@ final class RendererContext implements MarlinConst {
} }
if (doLogOverSize) { if (doLogOverSize) {
logInfo("getIntArray[oversize]: length=\t" + length + "\tfrom=\t" logInfo("getIntArray[oversize]: length=\t" + length);
+ getCallerInfo(className));
} }
return new int[length]; return new int[length];
...@@ -306,7 +302,7 @@ final class RendererContext implements MarlinConst { ...@@ -306,7 +302,7 @@ final class RendererContext implements MarlinConst {
if (doLogWidenArray) { if (doLogWidenArray) {
logInfo("widenIntArray[" + res.length + "]: usedSize=\t" logInfo("widenIntArray[" + res.length + "]: usedSize=\t"
+ usedSize + "\tlength=\t" + length + "\tneeded length=\t" + usedSize + "\tlength=\t" + length + "\tneeded length=\t"
+ needSize + "\tfrom=\t" + getCallerInfo(className)); + needSize);
} }
return res; return res;
} }
...@@ -338,8 +334,7 @@ final class RendererContext implements MarlinConst { ...@@ -338,8 +334,7 @@ final class RendererContext implements MarlinConst {
} }
if (doLogOverSize) { if (doLogOverSize) {
logInfo("getDirtyIntArray[oversize]: length=\t" + length logInfo("getDirtyIntArray[oversize]: length=\t" + length);
+ "\tfrom=\t" + getCallerInfo(className));
} }
return new int[length]; return new int[length];
...@@ -369,7 +364,7 @@ final class RendererContext implements MarlinConst { ...@@ -369,7 +364,7 @@ final class RendererContext implements MarlinConst {
if (doLogWidenArray) { if (doLogWidenArray) {
logInfo("widenDirtyIntArray[" + res.length + "]: usedSize=\t" logInfo("widenDirtyIntArray[" + res.length + "]: usedSize=\t"
+ usedSize + "\tlength=\t" + length + "\tneeded length=\t" + usedSize + "\tlength=\t" + length + "\tneeded length=\t"
+ needSize + "\tfrom=\t" + getCallerInfo(className)); + needSize);
} }
return res; return res;
} }
...@@ -399,8 +394,7 @@ final class RendererContext implements MarlinConst { ...@@ -399,8 +394,7 @@ final class RendererContext implements MarlinConst {
} }
if (doLogOverSize) { if (doLogOverSize) {
logInfo("getDirtyFloatArray[oversize]: length=\t" + length logInfo("getDirtyFloatArray[oversize]: length=\t" + length);
+ "\tfrom=\t" + getCallerInfo(className));
} }
return new float[length]; return new float[length];
...@@ -430,7 +424,7 @@ final class RendererContext implements MarlinConst { ...@@ -430,7 +424,7 @@ final class RendererContext implements MarlinConst {
if (doLogWidenArray) { if (doLogWidenArray) {
logInfo("widenDirtyFloatArray[" + res.length + "]: usedSize=\t" logInfo("widenDirtyFloatArray[" + res.length + "]: usedSize=\t"
+ usedSize + "\tlength=\t" + length + "\tneeded length=\t" + usedSize + "\tlength=\t" + length + "\tneeded length=\t"
+ needSize + "\tfrom=\t" + getCallerInfo(className)); + needSize);
} }
return res; return res;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册