add standard logging to NativeBigInteger
This commit is contained in:
@ -23,6 +23,9 @@ import freenet.support.CPUInformation.CPUInfo;
|
|||||||
import freenet.support.CPUInformation.IntelCPUInfo;
|
import freenet.support.CPUInformation.IntelCPUInfo;
|
||||||
import freenet.support.CPUInformation.UnknownCPUException;
|
import freenet.support.CPUInformation.UnknownCPUException;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>BigInteger that takes advantage of the jbigi library for the modPow operation,
|
* <p>BigInteger that takes advantage of the jbigi library for the modPow operation,
|
||||||
* which accounts for a massive segment of the processing cost of asymmetric
|
* which accounts for a massive segment of the processing cost of asymmetric
|
||||||
@ -89,6 +92,9 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
* do we want to dump some basic success/failure info to stderr during
|
* do we want to dump some basic success/failure info to stderr during
|
||||||
* initialization? this would otherwise use the Log component, but this makes
|
* initialization? this would otherwise use the Log component, but this makes
|
||||||
* it easier for other systems to reuse this class
|
* it easier for other systems to reuse this class
|
||||||
|
*
|
||||||
|
* Well, we really want to use Log so if you are one of those "other systems"
|
||||||
|
* then comment out the I2PAppContext usage below.
|
||||||
*/
|
*/
|
||||||
private static final boolean _doLog = System.getProperty("jbigi.dontLog") == null;
|
private static final boolean _doLog = System.getProperty("jbigi.dontLog") == null;
|
||||||
|
|
||||||
@ -401,38 +407,32 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
boolean loaded = loadGeneric("jbigi");
|
boolean loaded = loadGeneric("jbigi");
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
_nativeOk = true;
|
_nativeOk = true;
|
||||||
if (_doLog)
|
info("Locally optimized native BigInteger library loaded from the library path");
|
||||||
System.err.println("INFO: Locally optimized native BigInteger loaded from the library path");
|
|
||||||
} else {
|
} else {
|
||||||
loaded = loadFromResource("jbigi");
|
loaded = loadFromResource("jbigi");
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
_nativeOk = true;
|
_nativeOk = true;
|
||||||
if (_doLog)
|
info("Locally optimized native BigInteger library loaded from resource");
|
||||||
System.err.println("INFO: Locally optimized native BigInteger loaded from resource");
|
|
||||||
} else {
|
} else {
|
||||||
loaded = loadFromResource(true);
|
loaded = loadFromResource(true);
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
_nativeOk = true;
|
_nativeOk = true;
|
||||||
if (_doLog)
|
info("Optimized native BigInteger library '"+getResourceName(true)+"' loaded from resource");
|
||||||
System.err.println("INFO: Optimized native BigInteger library '"+getResourceName(true)+"' loaded from resource");
|
|
||||||
} else {
|
} else {
|
||||||
loaded = loadGeneric(true);
|
loaded = loadGeneric(true);
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
_nativeOk = true;
|
_nativeOk = true;
|
||||||
if (_doLog)
|
info("Optimized native BigInteger library '"+getMiddleName(true)+"' loaded from somewhere in the path");
|
||||||
System.err.println("INFO: Optimized native BigInteger library '"+getMiddleName(true)+"' loaded from somewhere in the path");
|
|
||||||
} else {
|
} else {
|
||||||
loaded = loadFromResource(false);
|
loaded = loadFromResource(false);
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
_nativeOk = true;
|
_nativeOk = true;
|
||||||
if (_doLog)
|
info("Non-optimized native BigInteger library '"+getResourceName(false)+"' loaded from resource");
|
||||||
System.err.println("INFO: Non-optimized native BigInteger library '"+getResourceName(false)+"' loaded from resource");
|
|
||||||
} else {
|
} else {
|
||||||
loaded = loadGeneric(false);
|
loaded = loadGeneric(false);
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
_nativeOk = true;
|
_nativeOk = true;
|
||||||
if (_doLog)
|
info("Non-optimized native BigInteger library '"+getMiddleName(false)+"' loaded from somewhere in the path");
|
||||||
System.err.println("INFO: Non-optimized native BigInteger library '"+getMiddleName(false)+"' loaded from somewhere in the path");
|
|
||||||
} else {
|
} else {
|
||||||
_nativeOk = false;
|
_nativeOk = false;
|
||||||
}
|
}
|
||||||
@ -442,14 +442,25 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_doLog && !_nativeOk)
|
if (!_nativeOk) {
|
||||||
System.err.println("INFO: Native BigInteger library jbigi not loaded - using pure java");
|
warn("Native BigInteger library jbigi not loaded - using pure Java - " +
|
||||||
}catch(Exception e){
|
"poor performance may result - see http://www.i2p2.i2p/jbigi.html for help");
|
||||||
if (_doLog) {
|
|
||||||
System.err.println("INFO: Native BigInteger library jbigi not loaded, reason: '"+e.getMessage()+"' - using pure java");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
warn("Native BigInteger library jbigi not loaded, reason: '"+e.getMessage()+"' - using pure java");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void info(String s) {
|
||||||
|
if(_doLog)
|
||||||
|
System.err.println("INFO: " + s);
|
||||||
|
I2PAppContext.getGlobalContext().logManager().getLog(NativeBigInteger.class).info(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void warn(String s) {
|
||||||
|
if(_doLog)
|
||||||
|
System.err.println("WARNING: " + s);
|
||||||
|
I2PAppContext.getGlobalContext().logManager().getLog(NativeBigInteger.class).warn(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user