CPUID: Fix saving of libjcpuid.jnifile on Macs,

was incorrectly saving as libjcpuid.so (tickets #1865, #1900)
 - Try to load libjcpuid-x86_64-osx.jnilib for 32-bit Macs,
   because as of 0.9.26 it's a 'fat binary' with 32-bit in it also.
   This was broken in the 0.9.26 changes.
 - Improve error logging
 - Add library search path logging to main()
NBI:
 - Try to load the "none" architecture for x86, even if
   CPUID loading fails (tickets #1865, #1900)
   This was broken in the 0.9.26 changes.
 - Add library search path logging to main()
 - Comment out unused method
This commit is contained in:
zzz
2017-03-06 20:44:16 +00:00
parent da00b95599
commit d573910b7a
4 changed files with 108 additions and 24 deletions

View File

@ -51,11 +51,8 @@ public class CPUID {
private static boolean _doLog = System.getProperty("jcpuid.dontLog") == null && private static boolean _doLog = System.getProperty("jcpuid.dontLog") == null &&
I2PAppContext.getGlobalContext().isRouterContext(); I2PAppContext.getGlobalContext().isRouterContext();
private static final boolean isX86 = System.getProperty("os.arch").contains("86") || private static final boolean isX86 = SystemVersion.isX86();
System.getProperty("os.arch").equals("amd64");
private static final boolean isWindows = SystemVersion.isWindows(); private static final boolean isWindows = SystemVersion.isWindows();
private static final String libPrefix = isWindows ? "" : "lib";
private static final String libSuffix = isWindows ? ".dll" : ".so";
private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux"); private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
private static final boolean isKFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("kfreebsd"); private static final boolean isKFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("kfreebsd");
private static final boolean isFreebsd = (!isKFreebsd) && System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd"); private static final boolean isFreebsd = (!isKFreebsd) && System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
@ -304,13 +301,15 @@ public class CPUID {
*/ */
public static CPUInfo getInfo() throws UnknownCPUException public static CPUInfo getInfo() throws UnknownCPUException
{ {
if(!_nativeOk) if(!_nativeOk) {
throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the jcpuid dll/so."); throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the " +
getLibraryPrefix() + "jcpuid " + getLibrarySuffix() + " file.");
}
String id = getCPUVendorID(); String id = getCPUVendorID();
if(id.equals("CentaurHauls")) if(id.equals("CentaurHauls"))
return new VIAInfoImpl(); return new VIAInfoImpl();
if(!isX86) if(!isX86)
throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPU's only"); throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPUs only.");
if(id.equals("AuthenticAMD")) if(id.equals("AuthenticAMD"))
return new AMDInfoImpl(); return new AMDInfoImpl();
if(id.equals("GenuineIntel")) if(id.equals("GenuineIntel"))
@ -321,9 +320,23 @@ public class CPUID {
public static void main(String args[]) public static void main(String args[])
{ {
_doLog = true; _doLog = true; // this is too late to log anything from above
if(!_nativeOk){ String path = System.getProperty("java.library.path");
System.out.println("**Failed to retrieve CPUInfo. Please verify the existence of jcpuid dll/so**"); String name = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
System.out.println("Native library search path: " + path);
if (_nativeOk) {
String sep = System.getProperty("path.separator");
String[] paths = DataHelper.split(path, sep);
for (String p : paths) {
File f = new File(p, name);
if (f.exists()) {
System.out.println("Found native library: " + f);
break;
}
}
} else {
System.out.println("Failed to retrieve CPUInfo. Please verify the existence of the " +
name + " file in the library path, or set -Djava.library.path=. in the command line");
} }
System.out.println("JCPUID Version: " + _jcpuidVersion); System.out.println("JCPUID Version: " + _jcpuidVersion);
System.out.println(" **CPUInfo**"); System.out.println(" **CPUInfo**");
@ -498,12 +511,22 @@ public class CPUID {
* *
*/ */
private static final boolean loadFromResource() { private static final boolean loadFromResource() {
// Mac info:
// Through 0.9.25, we had a libjcpuid-x86_64-osx.jnilib and a libjcpuid-x86-osx.jnilib file.
// As of 0.9.26, we have a single libjcpuid-x86_64-osx.jnilib fat binary that has both 64- and 32-bit support.
// For updates, the 0.9.27 update contained the new jbigi.jar.
// However, in rare cases, a user may have skipped that update, going straight
// from 0.9.26 to 0.9.28. Since we can't be sure, always try both for Mac.
// getResourceName64() returns non-null for 64-bit OR for 32-bit Mac.
// try 64 bit first, if getResourceName64() returns non-null // try 64 bit first, if getResourceName64() returns non-null
String resourceName = getResourceName64(); String resourceName = getResourceName64();
if (resourceName != null) { if (resourceName != null) {
boolean success = extractLoadAndCopy(resourceName); boolean success = extractLoadAndCopy(resourceName);
if (success) if (success)
return true; return true;
if (_doLog)
System.err.println("WARNING: Resource name [" + resourceName + "] was not found");
} }
// now try 32 bit // now try 32 bit
@ -511,7 +534,6 @@ public class CPUID {
boolean success = extractLoadAndCopy(resourceName); boolean success = extractLoadAndCopy(resourceName);
if (success) if (success)
return true; return true;
if (_doLog) if (_doLog)
System.err.println("WARNING: Resource name [" + resourceName + "] was not found"); System.err.println("WARNING: Resource name [" + resourceName + "] was not found");
return false; return false;
@ -531,7 +553,7 @@ public class CPUID {
return false; return false;
File outFile = null; File outFile = null;
FileOutputStream fos = null; FileOutputStream fos = null;
String filename = libPrefix + "jcpuid" + libSuffix; String filename = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
try { try {
InputStream libStream = resource.openStream(); InputStream libStream = resource.openStream();
outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename); outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename);
@ -571,17 +593,20 @@ public class CPUID {
/** @return non-null */ /** @return non-null */
private static final String getResourceName() private static final String getResourceName()
{ {
return getLibraryPrefix()+getLibraryMiddlePart()+"."+getLibrarySuffix(); return getLibraryPrefix() + getLibraryMiddlePart() + getLibrarySuffix();
} }
/** /**
* @return null if not on a 64 bit platform * @return null if not on a 64 bit platform (except Mac)
* @since 0.8.7 * @since 0.8.7
*/ */
private static final String getResourceName64() { private static final String getResourceName64() {
if (!is64) // As of GMP 6,
// libjcpuid-x86_64-osx.jnilib file is a fat binary that contains both 64- and 32-bit binaries
// See loadFromResource() for more info.
if (!is64 && !isMac)
return null; return null;
return getLibraryPrefix() + get64LibraryMiddlePart() + "." + getLibrarySuffix(); return getLibraryPrefix() + get64LibraryMiddlePart() + getLibrarySuffix();
} }
private static final String getLibraryPrefix() private static final String getLibraryPrefix()
@ -597,8 +622,14 @@ public class CPUID {
return "jcpuid-x86-windows"; // The convention on Windows return "jcpuid-x86-windows"; // The convention on Windows
if(isMac) { if(isMac) {
if(isX86) { if(isX86) {
return "jcpuid-x86-osx"; // The convention on Intel Macs // As of GMP6,
// our libjcpuid-x86_64.osx.jnilib is a fat binary,
// with the 32-bit lib in it also.
// Not sure if that was on purpose...
return "jcpuid-x86_64-osx"; // The convention on Intel Macs
} }
// this will fail, we don't have any ppc libs, but we can't return null here.
return "jcpuid-ppc-osx";
} }
if(isKFreebsd) if(isKFreebsd)
return "jcpuid-x86-kfreebsd"; // The convention on kfreebsd... return "jcpuid-x86-kfreebsd"; // The convention on kfreebsd...
@ -631,6 +662,8 @@ public class CPUID {
if(isX86){ if(isX86){
return "jcpuid-x86_64-osx"; return "jcpuid-x86_64-osx";
} }
// this will fail, we don't have any ppc libs, but we can't return null here.
return "jcpuid-ppc_64-osx";
} }
if(isSunos) if(isSunos)
return "jcpuid-x86_64-solaris"; return "jcpuid-x86_64-solaris";
@ -641,10 +674,10 @@ public class CPUID {
private static final String getLibrarySuffix() private static final String getLibrarySuffix()
{ {
if(isWindows) if(isWindows)
return "dll"; return ".dll";
if(isMac) if(isMac)
return "jnilib"; return ".jnilib";
else else
return "so"; return ".so";
} }
} }

View File

@ -209,6 +209,9 @@ public class NativeBigInteger extends BigInteger {
* Really this could be represented by a DAG, but the benefits don't * Really this could be represented by a DAG, but the benefits don't
* outweigh the implementation time. * outweigh the implementation time.
*/ */
// none -> {"none"), since 0.9.30
private final static String[] JBIGI_COMPAT_LIST_NONE = {JBIGI_OPTIMIZATION_X86};
private final static String[] JBIGI_COMPAT_LIST_PPC = {JBIGI_OPTIMIZATION_PPC}; private final static String[] JBIGI_COMPAT_LIST_PPC = {JBIGI_OPTIMIZATION_PPC};
private final static String[] JBIGI_COMPAT_LIST_ARM = {JBIGI_OPTIMIZATION_ARM_CORTEX_A15, JBIGI_OPTIMIZATION_ARM_CORTEX_A9, JBIGI_OPTIMIZATION_ARM_CORTEX_A8, private final static String[] JBIGI_COMPAT_LIST_ARM = {JBIGI_OPTIMIZATION_ARM_CORTEX_A15, JBIGI_OPTIMIZATION_ARM_CORTEX_A9, JBIGI_OPTIMIZATION_ARM_CORTEX_A8,
JBIGI_OPTIMIZATION_ARM_CORTEX_A7, JBIGI_OPTIMIZATION_ARM_CORTEX_A5, JBIGI_OPTIMIZATION_ARM_ARMV7, JBIGI_OPTIMIZATION_ARM_CORTEX_A7, JBIGI_OPTIMIZATION_ARM_CORTEX_A5, JBIGI_OPTIMIZATION_ARM_ARMV7,
@ -231,11 +234,14 @@ public class NativeBigInteger extends BigInteger {
private final static String[] JBIGI_COMPAT_LIST_INTEL_CORE = {JBIGI_OPTIMIZATION_COREI_BWL, JBIGI_OPTIMIZATION_COREI_HWL, JBIGI_OPTIMIZATION_COREI_SBR, private final static String[] JBIGI_COMPAT_LIST_INTEL_CORE = {JBIGI_OPTIMIZATION_COREI_BWL, JBIGI_OPTIMIZATION_COREI_HWL, JBIGI_OPTIMIZATION_COREI_SBR,
JBIGI_OPTIMIZATION_COREI, JBIGI_OPTIMIZATION_CORE2, JBIGI_OPTIMIZATION_PENTIUMM, JBIGI_OPTIMIZATION_COREI, JBIGI_OPTIMIZATION_CORE2, JBIGI_OPTIMIZATION_PENTIUMM,
JBIGI_OPTIMIZATION_PENTIUM3, JBIGI_OPTIMIZATION_X86}; JBIGI_OPTIMIZATION_PENTIUM3, JBIGI_OPTIMIZATION_X86};
/** /**
* The mapping between CPU architecture and its compatibility list. * The mapping between CPU architecture and its compatibility list.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
private final static HashMap<String, String[]> JBIGI_COMPAT_MAP = new HashMap<String, String[]>() {{ private final static HashMap<String, String[]> JBIGI_COMPAT_MAP = new HashMap<String, String[]>() {{
// none -> {"none"), since 0.9.30
put(JBIGI_OPTIMIZATION_X86, JBIGI_COMPAT_LIST_NONE);
put(JBIGI_OPTIMIZATION_PPC, JBIGI_COMPAT_LIST_PPC); put(JBIGI_OPTIMIZATION_PPC, JBIGI_COMPAT_LIST_PPC);
put(JBIGI_OPTIMIZATION_ARM_ARMV5, JBIGI_COMPAT_LIST_ARM); put(JBIGI_OPTIMIZATION_ARM_ARMV5, JBIGI_COMPAT_LIST_ARM);
@ -406,10 +412,11 @@ public class NativeBigInteger extends BigInteger {
if (intelcpu.IsPentiumCompatible()) if (intelcpu.IsPentiumCompatible())
return JBIGI_OPTIMIZATION_PENTIUM; return JBIGI_OPTIMIZATION_PENTIUM;
} }
return null;
} catch (UnknownCPUException e) { } catch (UnknownCPUException e) {
return null;
} }
// always try "none" if we don't know the x86 type,
// in case of CPUID fail or not finding compatibility above
return JBIGI_OPTIMIZATION_X86;
} else if (_isArm) { } else if (_isArm) {
if (_isWin) if (_isWin)
return null; return null;
@ -739,9 +746,25 @@ public class NativeBigInteger extends BigInteger {
*/ */
public static void main(String args[]) { public static void main(String args[]) {
_doLog = true; _doLog = true;
String path = System.getProperty("java.library.path");
String name = _libPrefix + "jbigi" + _libSuffix;
System.out.println("Native library search path: " + path);
if (_nativeOk) {
String sep = System.getProperty("path.separator");
String[] paths = DataHelper.split(path, sep);
for (String p : paths) {
File f = new File(p, name);
if (f.exists()) {
System.out.println("Found native library: " + f);
break;
}
}
} else {
System.out.println("Failed to load native library. Please verify the existence of the " +
name + " file in the library path, or set -Djava.library.path=. in the command line");
}
boolean nativeOnly = args.length > 0 && args[0].equals("-n"); boolean nativeOnly = args.length > 0 && args[0].equals("-n");
if (nativeOnly && !_nativeOk) { if (nativeOnly && !_nativeOk) {
System.out.println("Failed to load native library");
System.exit(1); System.exit(1);
} }
if (_nativeOk) { if (_nativeOk) {
@ -1141,6 +1164,7 @@ public class NativeBigInteger extends BigInteger {
return Collections.emptyList(); return Collections.emptyList();
List<String> rv = new ArrayList<String>(20); List<String> rv = new ArrayList<String>(20);
String primary = getMiddleName2(true); String primary = getMiddleName2(true);
// primary may be null
String[] compatList = JBIGI_COMPAT_MAP.get(primary); String[] compatList = JBIGI_COMPAT_MAP.get(primary);
if (primary != null && compatList == null) { if (primary != null && compatList == null) {
@ -1222,12 +1246,14 @@ public class NativeBigInteger extends BigInteger {
/** /**
* @return may be null if optimized is true; returns jbigi-xxx-none if optimize is false * @return may be null if optimized is true; returns jbigi-xxx-none if optimize is false
*/ */
/****
private static final String getMiddleName(boolean optimized) { private static final String getMiddleName(boolean optimized) {
String m2 = getMiddleName2(optimized); String m2 = getMiddleName2(optimized);
if (m2 == null) if (m2 == null)
return null; return null;
return getMiddleName1() + m2; return getMiddleName1() + m2;
} }
****/
/** /**
* @return may be null if optimized is true; returns "none" if optimize is false * @return may be null if optimized is true; returns "none" if optimize is false

View File

@ -1,3 +1,28 @@
2017-03-06 zzz
* CPUID:
- Fix saving of libjcpuid.jnifile on Macs,
was incorrectly saving as libjcpuid.so (tickets #1865, #1900)
- Try to load libjcpuid-x86_64-osx.jnilib for 32-bit Macs,
because as of 0.9.26 it's a 'fat binary' with 32-bit in it also.
- Add library search path logging to main()
* NBI:
- Try to load the "none" architecture for x86, even if
CPUID loading fails (tickets #1865, #1900)
- Add library search path logging to main()
* Throttle: Fix disable of probabalistic throttling
(ticket #1963) (thx mysterious)
2017-03-03 zzz
* Utils: Fix crash in Windows installer
2017-03-02 zzz
* SSU:
- Initial work on introducer expiration (proposal 133)
- Fix bug in error handling for introduction parameters in RI
2017-03-01 zzz
* Servlet: Catch OOM in MultiPartRequest
2017-02-27 zzz 2017-02-27 zzz
* i2psnark: Fix disappearing start button * i2psnark: Fix disappearing start button
* addressbook: Add date parameter to authentication strings * addressbook: Add date parameter to authentication strings

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 1; public final static long BUILD = 2;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";