Changeset d573910b


Ignore:
Timestamp:
Mar 6, 2017 8:44:16 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
23ee40d
Parents:
da00b955
Message:

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
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/freenet/support/CPUInformation/CPUID.java

    rda00b955 rd573910b  
    5252                                    I2PAppContext.getGlobalContext().isRouterContext();
    5353
    54     private static final boolean isX86 = System.getProperty("os.arch").contains("86") ||
    55                                          System.getProperty("os.arch").equals("amd64");
     54    private static final boolean isX86 = SystemVersion.isX86();
    5655    private static final boolean isWindows = SystemVersion.isWindows();
    57     private static final String libPrefix = isWindows ? "" : "lib";
    58     private static final String libSuffix = isWindows ? ".dll" : ".so";
    5956    private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
    6057    private static final boolean isKFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("kfreebsd");
     
    305302    public static CPUInfo getInfo() throws UnknownCPUException
    306303    {
    307         if(!_nativeOk)
    308             throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the jcpuid dll/so.");
     304        if(!_nativeOk) {
     305            throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the " +
     306                                          getLibraryPrefix() + "jcpuid " + getLibrarySuffix() + " file.");
     307        }
    309308        String id = getCPUVendorID();
    310309        if(id.equals("CentaurHauls"))
    311310            return new VIAInfoImpl();
    312311        if(!isX86)
    313             throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPU's only");
     312            throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPUs only.");
    314313        if(id.equals("AuthenticAMD"))
    315314            return new AMDInfoImpl();
     
    322321    public static void main(String args[])
    323322    {
    324         _doLog = true;
    325         if(!_nativeOk){
    326             System.out.println("**Failed to retrieve CPUInfo. Please verify the existence of jcpuid dll/so**");
     323        _doLog = true; // this is too late to log anything from above
     324        String path = System.getProperty("java.library.path");
     325        String name = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
     326        System.out.println("Native library search path: " + path);
     327        if (_nativeOk) {
     328            String sep = System.getProperty("path.separator");
     329            String[] paths = DataHelper.split(path, sep);
     330            for (String p : paths) {
     331                File f = new File(p, name);
     332                if (f.exists()) {
     333                    System.out.println("Found native library: " + f);
     334                    break;
     335                }
     336            }
     337        } else {
     338            System.out.println("Failed to retrieve CPUInfo. Please verify the existence of the " +
     339                               name + " file in the library path, or set -Djava.library.path=. in the command line");
    327340        }
    328341        System.out.println("JCPUID Version: " + _jcpuidVersion);
     
    499512     */
    500513    private static final boolean loadFromResource() {
     514        // Mac info:
     515        // Through 0.9.25, we had a libjcpuid-x86_64-osx.jnilib and a libjcpuid-x86-osx.jnilib file.
     516        // As of 0.9.26, we have a single libjcpuid-x86_64-osx.jnilib fat binary that has both 64- and 32-bit support.
     517        // For updates, the 0.9.27 update contained the new jbigi.jar.
     518        // However, in rare cases, a user may have skipped that update, going straight
     519        // from 0.9.26 to 0.9.28. Since we can't be sure, always try both for Mac.
     520        // getResourceName64() returns non-null for 64-bit OR for 32-bit Mac.
     521
    501522        // try 64 bit first, if getResourceName64() returns non-null
    502523        String resourceName = getResourceName64();
     
    505526            if (success)
    506527                return true;
     528            if (_doLog)
     529                System.err.println("WARNING: Resource name [" + resourceName + "] was not found");
    507530        }
    508531
     
    512535        if (success)
    513536            return true;
    514 
    515537        if (_doLog)
    516538            System.err.println("WARNING: Resource name [" + resourceName + "] was not found");
     
    532554        File outFile = null;
    533555        FileOutputStream fos = null;
    534         String filename = libPrefix + "jcpuid" + libSuffix;
     556        String filename = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
    535557        try {
    536558            InputStream libStream = resource.openStream();
     
    572594    private static final String getResourceName()
    573595    {
    574         return getLibraryPrefix()+getLibraryMiddlePart()+"."+getLibrarySuffix();
    575     }
    576 
    577     /**
    578      * @return null if not on a 64 bit platform
     596        return getLibraryPrefix() + getLibraryMiddlePart() + getLibrarySuffix();
     597    }
     598
     599    /**
     600     * @return null if not on a 64 bit platform (except Mac)
    579601     * @since 0.8.7
    580602     */
    581603    private static final String getResourceName64() {
    582         if (!is64)
     604        // As of GMP 6,
     605        // libjcpuid-x86_64-osx.jnilib file is a fat binary that contains both 64- and 32-bit binaries
     606        // See loadFromResource() for more info.
     607        if (!is64 && !isMac)
    583608            return null;
    584         return getLibraryPrefix() + get64LibraryMiddlePart() + "." + getLibrarySuffix();
     609        return getLibraryPrefix() + get64LibraryMiddlePart() + getLibrarySuffix();
    585610    }
    586611
     
    598623        if(isMac) {
    599624            if(isX86) {
    600                 return "jcpuid-x86-osx";  // The convention on Intel Macs
     625                // As of GMP6,
     626                // our libjcpuid-x86_64.osx.jnilib is a fat binary,
     627                // with the 32-bit lib in it also.
     628                // Not sure if that was on purpose...
     629                return "jcpuid-x86_64-osx";  // The convention on Intel Macs
    601630            }
     631            // this will fail, we don't have any ppc libs, but we can't return null here.
     632            return "jcpuid-ppc-osx";
    602633        }
    603634        if(isKFreebsd)
     
    632663                return "jcpuid-x86_64-osx";
    633664            }
     665            // this will fail, we don't have any ppc libs, but we can't return null here.
     666            return "jcpuid-ppc_64-osx";
    634667        }
    635668        if(isSunos)
     
    642675    {
    643676        if(isWindows)
    644             return "dll";
     677            return ".dll";
    645678        if(isMac)
    646             return "jnilib";
     679            return ".jnilib";
    647680        else
    648             return "so";
     681            return ".so";
    649682    }
    650683}
  • core/java/src/net/i2p/util/NativeBigInteger.java

    rda00b955 rd573910b  
    210210     * outweigh the implementation time.
    211211     */
     212
     213    // none -> {"none"), since 0.9.30
     214    private final static String[] JBIGI_COMPAT_LIST_NONE          = {JBIGI_OPTIMIZATION_X86};
    212215    private final static String[] JBIGI_COMPAT_LIST_PPC           = {JBIGI_OPTIMIZATION_PPC};
    213216    private final static String[] JBIGI_COMPAT_LIST_ARM           = {JBIGI_OPTIMIZATION_ARM_CORTEX_A15, JBIGI_OPTIMIZATION_ARM_CORTEX_A9, JBIGI_OPTIMIZATION_ARM_CORTEX_A8,
     
    232235                                                                     JBIGI_OPTIMIZATION_COREI, JBIGI_OPTIMIZATION_CORE2, JBIGI_OPTIMIZATION_PENTIUMM,
    233236                                                                     JBIGI_OPTIMIZATION_PENTIUM3, JBIGI_OPTIMIZATION_X86};
     237
    234238    /**
    235239     * The mapping between CPU architecture and its compatibility list.
     
    237241    @SuppressWarnings("serial")
    238242    private final static HashMap<String, String[]> JBIGI_COMPAT_MAP = new HashMap<String, String[]>() {{
     243        // none -> {"none"), since 0.9.30
     244        put(JBIGI_OPTIMIZATION_X86, JBIGI_COMPAT_LIST_NONE);
    239245        put(JBIGI_OPTIMIZATION_PPC, JBIGI_COMPAT_LIST_PPC);
    240246
     
    407413                        return JBIGI_OPTIMIZATION_PENTIUM;
    408414                }
    409                 return null;
    410415            } catch (UnknownCPUException e) {
    411                 return null;
    412             }
     416            }
     417            // always try "none" if we don't know the x86 type,
     418            // in case of CPUID fail or not finding compatibility above
     419            return JBIGI_OPTIMIZATION_X86;
    413420        } else if (_isArm) {
    414421            if (_isWin)
     
    740747    public static void main(String args[]) {
    741748        _doLog = true;
     749        String path = System.getProperty("java.library.path");
     750        String name = _libPrefix + "jbigi" + _libSuffix;
     751        System.out.println("Native library search path: " + path);
     752        if (_nativeOk) {
     753            String sep = System.getProperty("path.separator");
     754            String[] paths = DataHelper.split(path, sep);
     755            for (String p : paths) {
     756                File f = new File(p, name);
     757                if (f.exists()) {
     758                    System.out.println("Found native library: " + f);
     759                    break;
     760                }
     761            }
     762        } else {
     763            System.out.println("Failed to load native library. Please verify the existence of the " +
     764                               name + " file in the library path, or set -Djava.library.path=. in the command line");
     765        }
    742766        boolean nativeOnly = args.length > 0 && args[0].equals("-n");
    743767        if (nativeOnly && !_nativeOk) {
    744             System.out.println("Failed to load native library");
    745768            System.exit(1);
    746769        }
     
    11421165        List<String> rv = new ArrayList<String>(20);
    11431166        String primary = getMiddleName2(true);
     1167        // primary may be null
    11441168        String[] compatList = JBIGI_COMPAT_MAP.get(primary);
    11451169
     
    12231247     *  @return may be null if optimized is true; returns jbigi-xxx-none if optimize is false
    12241248     */
     1249/****
    12251250    private static final String getMiddleName(boolean optimized) {
    12261251        String m2 = getMiddleName2(optimized);
     
    12291254        return getMiddleName1() + m2;
    12301255    }
     1256****/
    12311257
    12321258    /**
  • history.txt

    rda00b955 rd573910b  
     12017-03-06 zzz
     2 * CPUID:
     3   - Fix saving of libjcpuid.jnifile on Macs,
     4     was incorrectly saving as libjcpuid.so (tickets #1865, #1900)
     5   - Try to load libjcpuid-x86_64-osx.jnilib for 32-bit Macs,
     6     because as of 0.9.26 it's a 'fat binary' with 32-bit in it also.
     7   - Add library search path logging to main()
     8 * NBI:
     9   - Try to load the "none" architecture for x86, even if
     10     CPUID loading fails (tickets #1865, #1900)
     11   - Add library search path logging to main()
     12 * Throttle: Fix disable of probabalistic throttling
     13   (ticket #1963) (thx mysterious)
     14
     152017-03-03 zzz
     16 * Utils: Fix crash in Windows installer
     17
     182017-03-02 zzz
     19 * SSU:
     20   - Initial work on introducer expiration (proposal 133)
     21   - Fix bug in error handling for introduction parameters in RI
     22
     232017-03-01 zzz
     24 * Servlet: Catch OOM in MultiPartRequest
     25
    1262017-02-27 zzz
    227 * i2psnark: Fix disappearing start button
  • router/java/src/net/i2p/router/RouterVersion.java

    rda00b955 rd573910b  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 1;
     21    public final static long BUILD = 2;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.