I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit f7f05cfc authored by jrandom's avatar jrandom Committed by zzz
Browse files

imported Iakin's public domain jcpuid library allowing the detection of CPU types from java

imported Iakin's modifications to jbigi to use the jcpuid library in detecting what jbigi implementation to load
imported and slightly updated Iakin's scripts to build jbigi for lots of architectures
(yay iakin!)
parent f4754d74
No related branches found
No related tags found
No related merge requests found
Showing
with 1362 additions and 35 deletions
Prior to building the jbigi library, you will need to fetch the GMP source
from http://www.swox.com/gmp/, saving it to jbigi/gmp-4.1.3.tar.bz2 (it will
be unpacked and built as necessary).
To build the native jbigi and jcpuid libraries for the current host CPU,
simply run sh build.sh and the results will be packaged up into jbigi.jar
To build the native jbigi libraries for all supported CPUs (on the current OS),
go into jbigi/ and run build-all.sh (the results will be under jbigi/lib/)
#!/bin/sh #/bin/sh
# linux settings:
CC="gcc"
ANT="ant"
JAVA="java"
COMPILEFLAGS="-fPIC -Wall" (cd jcpuid ; sh build.sh ; cd ..)
LINKFLAGS="-shared -Wl,-soname,libjbigi.so" (cd jbigi ; sh build.sh ; cd ..)
INCLUDES="-Iinclude -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" mkdir -p t/freenet/support/CPUInformation/
INCLUDELIBS="-lgmp" cp jcpuid/lib/freenet/support/CPUInformation/*jcpuid-* t/freenet/support/CPUInformation/
STATICLIBS=""
LIBFILE="libjbigi.so" mkdir -p t/net/i2p/util/
cp jbigi/lib/net/i2p/util/*jbigi-* t/net/i2p/util/
# jrandom's mingw setup: (cd t ; jar cf ../jbigi.jar . ; cd ..)
#COMPILEFLAGS="-Wall"
#INCLUDES="-Iinclude -Ic:/software/j2sdk1.4.2/include/win32/ -Ic:/software/j2sdk1.4.2/include/ -Ic:/dev/gmp-4.1.2/"
#LINKFLAGS="-shared -Wl,--kill-at"
#LIBFILE="jbigi.dll"
#INCLUDELIBS=""
#STATICLIBS="libgmp.a"
echo "Compiling C code..." echo "Native code built into jbigi.jar"
rm -f jbigi.o $LIBFILE
$CC -c $COMPILEFLAGS $INCLUDES src/jbigi.c
$CC $LINKFLAGS $INCLUDES $INCLUDELIBS -o $LIBFILE jbigi.o $STATICLIBS
echo ""
echo "Doing an ant build..."
(cd ../java/ ; $ANT build)
echo ""
echo "Built, now testing... This will take a while."
LD_LIBRARY_PATH=. $JAVA -cp ../java/build/i2p.jar -DloggerConfigLocation=../../installer/java/src/logger.config.template net.i2p.util.NativeBigInteger
echo ""
echo ""
echo "Test complete. Please review the lines 'native run time:', 'java run time:', and 'native = '"
***net.i2p.util.NativeBigInteger, native part of the code****
Execute the build.sh script to produce jbigi library files optimized for a number of different CPU-types.
TODO: What is jbigi
TODO: Document generated folder structure
TODO: Instructions for adding the libraries to a jar
Linux-specific information:
Some linux distributions comes bundled with GMP. There is currently no out-of-the-box support for this in the current build-scripts.
Windows-specific information:
The best way of building the jbigi dll's is to install Mingw {URL} and msys {URL}. The combination of these two should be able to run the included build-scripts without modifications.
\ No newline at end of file
#/bin/sh
case `uname -sr` in
MINGW*)
echo "Building windows .dlls for all architectures";;
Linux*)
echo "Building linux .sos for all architectures";;
FreeBSD*)
echo "Building freebsd .sos for all architectures";;
*)
echo "Unsupported build environment"
exit;;
esac
echo "Extracting GMP..."
tar -xzf gmp-4.1.3.tar.gz
echo "Building..."
mkdir bin
mkdir lib
mkdir lib/net
mkdir lib/net/i2p
mkdir lib/net/i2p/util
for x in none pentium pentiummmx pentium2 pentium3 pentium4 k6 k62 k63 athlon
do
mkdir bin/$x
cd bin/$x
../../gmp-4.1.3/configure --build=$x
make
sh ../../build_jbigi.sh static
case `uname -sr` in
MINGW*)
cp jbigi.dll ../../lib/net/i2p/util/jbigi-windows-$x.dll;;
Linux*)
cp libjbigi.so ../../lib/net/i2p/util/libjbigi-linux-$x.so;;
FreeBSD*)
cp libjbigi.so ../../lib/net/i2p/util/libjbigi-freebsd-$x.so;;
esac
cd ..
cd ..
done
#/bin/sh
case `uname -sr` in
MINGW*)
echo "Building windows .dll's";;
CYGWIN*)
echo "Building windows .dll's";;
Linux*)
echo "Building linux .so's";;
FreeBSD*)
echo "Building freebsd .so's";;
*)
echo "Unsupported build environment"
exit;;
esac
echo "Extracting GMP..."
tar -xzf gmp-4.1.3.tar.gz
echo "Building..."
mkdir bin
mkdir lib
mkdir lib/net
mkdir lib/net/i2p
mkdir lib/net/i2p/util
mkdir bin/local
cd bin/local
../../gmp-4.1.3/configure
make
sh ../../build_jbigi.sh static
case `uname -sr` in
MINGW*)
cp jbigi.dll ../../lib/net/i2p/util/jbigi-windows-x86.dll;;
CYGWIN*)
cp jbigi.dll ../../lib/net/i2p/util/jbigi-windows-x86.dll;;
Linux*)
cp libjbigi.so ../../lib/net/i2p/util/libjbigi-linux-x86.so;;
FreeBSD*)
cp libjbigi.so ../../lib/net/i2p/util/libjbigi-freebsd-x86.so;;
esac
cd ..
cd ..
#!/bin/sh
# When executed in Mingw: Produces an jbigi.dll
# When executed in Linux: Produces an libjbigi.so
CC="gcc"
case `uname -sr` in
MINGW*)
JAVA_HOME="c:/software/j2sdk1.4.2_05"
COMPILEFLAGS="-Wall"
INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/"
LINKFLAGS="-shared -Wl,--kill-at"
LIBFILE="jbigi.dll";;
CYGWIN*)
JAVA_HOME="c:/software/j2sdk1.4.2_05"
COMPILEFLAGS="-Wall -mno-cygwin"
INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/"
LINKFLAGS="-shared -Wl,--kill-at"
LIBFILE="jbigi.dll";;
*)
COMPILEFLAGS="-fPIC -Wall"
INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
LINKFLAGS="-shared -Wl,-soname,libjbigi.so"
LIBFILE="libjbigi.so";;
esac
#To link dynamically to GMP (use libgmp.so or gmp.lib), uncomment the first line below
#To link statically to GMP, uncomment the second line below
if test $1 = "dynamic"
then
echo "Building jbigi lib that is dynamically linked to GMP"
LIBPATH="-L.libs"
INCLUDELIBS="-lgmp"
else
echo "Building jbigi lib that is statically linked to GMP"
STATICLIBS=".libs/libgmp.a"
fi
echo "Compiling C code..."
rm -f jbigi.o $LIBFILE
$CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c
$CC $LINKFLAGS $INCLUDES $INCLUDELIBS -o $LIBFILE jbigi.o $STATICLIBS
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_i2p_util_NativeBigInteger */
#ifndef _Included_net_i2p_util_NativeBigInteger
#define _Included_net_i2p_util_NativeBigInteger
#ifdef __cplusplus
extern "C" {
#endif
#undef net_i2p_util_NativeBigInteger_serialVersionUID
#define net_i2p_util_NativeBigInteger_serialVersionUID -8742448824652078965i64
#undef net_i2p_util_NativeBigInteger_LONG_MASK
#define net_i2p_util_NativeBigInteger_LONG_MASK 4294967295i64
/* Inaccessible static: bitsPerDigit */
#undef net_i2p_util_NativeBigInteger_SMALL_PRIME_THRESHOLD
#define net_i2p_util_NativeBigInteger_SMALL_PRIME_THRESHOLD 95L
/* Inaccessible static: SMALL_PRIME_PRODUCT */
#undef net_i2p_util_NativeBigInteger_MAX_CONSTANT
#define net_i2p_util_NativeBigInteger_MAX_CONSTANT 16L
/* Inaccessible static: posConst */
/* Inaccessible static: negConst */
/* Inaccessible static: ZERO */
/* Inaccessible static: ONE */
/* Inaccessible static: TWO */
/* Inaccessible static: bnExpModThreshTable */
/* Inaccessible static: trailingZeroTable */
/* Inaccessible static: zeros */
/* Inaccessible static: digitsPerLong */
/* Inaccessible static: longRadix */
/* Inaccessible static: digitsPerInt */
/* Inaccessible static: intRadix */
#undef net_i2p_util_NativeBigInteger_serialVersionUID
#define net_i2p_util_NativeBigInteger_serialVersionUID -8287574255936472291i64
/* Inaccessible static: serialPersistentFields */
/* Inaccessible static: array_00024B */
/* Inaccessible static: _nativeOk */
#undef net_i2p_util_NativeBigInteger__doLog
#define net_i2p_util_NativeBigInteger__doLog 1L
/* Inaccessible static: DEFAULT_REF_FILENAME */
/* Inaccessible static: _sampleGenerator */
/* Inaccessible static: _samplePrime */
/* Inaccessible static: class_000240 */
/*
* Class: net_i2p_util_NativeBigInteger
* Method: nativeModPow
* Signature: ([B[B[B)[B
*/
JNIEXPORT jbyteArray JNICALL Java_net_i2p_util_NativeBigInteger_nativeModPow
(JNIEnv *, jclass, jbyteArray, jbyteArray, jbyteArray);
/*
* Class: net_i2p_util_NativeBigInteger
* Method: nativeDoubleValue
* Signature: ([B)D
*/
JNIEXPORT jdouble JNICALL Java_net_i2p_util_NativeBigInteger_nativeDoubleValue
(JNIEnv *, jclass, jbyteArray);
#ifdef __cplusplus
}
#endif
#endif
#include <stdio.h>
#include <gmp.h>
#include "jbigi.h"
/******** prototypes */
void convert_j2mp(JNIEnv* env, jbyteArray jvalue, mpz_t* mvalue);
void convert_mp2j(JNIEnv* env, mpz_t mvalue, jbyteArray* jvalue);
/*****************************************
*****Native method implementations*******
*****************************************/
/******** nativeModPow() */
/*
* Class: net_i2p_util_NativeBigInteger
* Method: nativeModPow
* Signature: ([B[B[B)[B
*
* From the javadoc:
*
* calculate (base ^ exponent) % modulus.
* @param curVal big endian twos complement representation of the base (but it must be positive)
* @param exponent big endian twos complement representation of the exponent
* @param modulus big endian twos complement representation of the modulus
* @return big endian twos complement representation of (base ^ exponent) % modulus
*/
JNIEXPORT jbyteArray JNICALL Java_net_i2p_util_NativeBigInteger_nativeModPow
(JNIEnv* env, jclass cls, jbyteArray jbase, jbyteArray jexp, jbyteArray jmod) {
/* 1) Convert base, exponent, modulus into the format libgmp understands
* 2) Call libgmp's modPow.
* 3) Convert libgmp's result into a big endian twos complement number.
*/
mpz_t mbase;
mpz_t mexp;
mpz_t mmod;
jbyteArray jresult;
convert_j2mp(env, jbase, &mbase);
convert_j2mp(env, jexp, &mexp);
convert_j2mp(env, jmod, &mmod);
/* Perform the actual powmod. We use mmod for the result because it is
* always at least as big as the result.
*/
mpz_powm(mmod, mbase, mexp, mmod);
convert_mp2j(env, mmod, &jresult);
mpz_clear(mbase);
mpz_clear(mexp);
mpz_clear(mmod);
return jresult;
}
/******** nativeDoubleValue() */
/*
* Class: net_i2p_util_NativeBigInteger
* Method: nativeDoubleValue
* Signature: ([B)D
*
* From the Javadoc:
*
* Converts a BigInteger byte-array to a 'double'
* @param ba Big endian twos complement representation of the BigInteger to convert to a double
* @return The plain double-value represented by 'ba'
*/
JNIEXPORT jdouble JNICALL Java_net_i2p_util_NativeBigInteger_nativeDoubleValue
(JNIEnv * env, jclass cls, jbyteArray jba){
/* 1) Convert the bytearray BigInteger value into the format libgmp understands
* 2) Call libgmp's mpz_get_d.
* 3) Convert libgmp's result into a big endian twos complement number.
*/
mpz_t mval;
jdouble retval;
convert_j2mp(env, jba, &mval);
retval = mpz_get_d(mval);
mpz_clear(mval);
return retval;
}
/******************************
*****Conversion methods*******
******************************/
/*Luckily we can use GMP's mpz_import() and mpz_export() functions to convert from/to
*BigInteger.toByteArray() representation.
*/
/******** convert_j2mp() */
/*
* Initializes the GMP value with enough preallocated size, and converts the
* Java value into the GMP value. The value that mvalue points to should be
* uninitialized
*/
void convert_j2mp(JNIEnv* env, jbyteArray jvalue, mpz_t* mvalue)
{
jsize size;
jbyte* jbuffer;
//int sign;
size = (*env)->GetArrayLength(env, jvalue);
jbuffer = (*env)->GetByteArrayElements(env, jvalue, NULL);
mpz_init2(*mvalue, sizeof(jbyte) * 8 * size); //preallocate the size
/* void mpz_import(
* mpz_t rop, size_t count, int order, int size, int endian,
* size_t nails, const void *op);
*
* order = 1
* order can be 1 for most significant word first or -1 for least
* significant first.
* endian = 1
* Within each word endian can be 1 for most significant byte first,
* -1 for least significant first.
* nails = 0
* The most significant nails bits of each word are skipped, this can
* be 0 to use the full words.
*/
mpz_import(*mvalue, size, 1, sizeof(jbyte), 1, 0, (void*)jbuffer);
/*Uncomment this to support negative integer values,
not tested though..
sign = jbuffer[0] < 0?-1:1;
if(sign == -1)
mpz_neg(*mvalue,*mvalue);
*/
(*env)->ReleaseByteArrayElements(env, jvalue, jbuffer, JNI_ABORT);
}
/******** convert_mp2j() */
/*
* Converts the GMP value into the Java value; Doesn't do anything else.
* Pads the resulting jbyte array with 0, so the twos complement value is always
* positive.
*/
void convert_mp2j(JNIEnv* env, mpz_t mvalue, jbyteArray* jvalue)
{
jsize size;
jbyte* buffer;
jboolean copy;
//int i;
copy = JNI_FALSE;
/* sizeinbase() + 7 => Ceil division */
size = (mpz_sizeinbase(mvalue, 2) + 7) / 8 + sizeof(jbyte);
*jvalue = (*env)->NewByteArray(env, size);
buffer = (*env)->GetByteArrayElements(env, *jvalue, &copy);
buffer[0] = 0x00;
//Uncomment the comments below to support negative integer values,
//not very well-tested though..
//if(mpz_sgn(mvalue) >=0){
mpz_export((void*)&buffer[1], &size, 1, sizeof(jbyte), 1, 0, mvalue);
//}else{
// mpz_add_ui(mvalue,mvalue,1);
// mpz_export((void*)&buffer[1], &size, 1, sizeof(jbyte), 1, 0, mvalue);
// for(i =0;i<=size;i++){ //This could be done more effectively
// buffer[i]=~buffer[i];
// }
//}
/* mode has (supposedly) no effect if elems is not a copy of the
* elements in array
*/
(*env)->ReleaseByteArrayElements(env, *jvalue, buffer, 0);
//mode has (supposedly) no effect if elems is not a copy of the elements in array
}
/******** eof */
#/bin/sh
case `uname -sr` in
MINGW*)
echo "Building windows .dll's";;
CYGWIN*)
echo "Building windows .dll's";;
Linux*)
echo "Building linux .so's";;
FreeBSD*)
echo "Building freebsd .so's";;
*)
echo "Unsupported build environment"
exit;;
esac
rm -rf lib
mkdir lib
mkdir lib/freenet
mkdir lib/freenet/support
mkdir lib/freenet/support/CPUInformation
CPP="g++"
case `uname -sr` in
MINGW*)
JAVA_HOME="/c/software/j2sdk1.4.2_05"
COMPILEFLAGS="-Wall"
INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/ -I$JAVA_HOME/include/win32/"
LINKFLAGS="-shared -static -static-libgcc -Wl,--kill-at"
LIBFILE="lib/freenet/support/CPUInformation/jcpuid-x86-windows.dll";;
FreeBSD*)
COMPILEFLAGS="-Wall"
INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/ -I$JAVA_HOME/include/freebsd/"
LINKFLAGS="-shared -static -static-libgcc -Wl,-soname,libjcpuid-x86-freebsd.so"
LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-freebsd.so";;
Linux*)
COMPILEFLAGS="-fPIC -Wall"
INCLUDES="-I. -Iinclude -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
LINKFLAGS="-shared -static -static-libgcc -Wl,-soname,libjcpuid-x86-linux.so"
LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-linux.so";;
esac
echo "Compiling C code..."
rm -f $LIBFILE
$CPP $LINKFLAGS $INCLUDES src/*.cpp -o $LIBFILE
strip $LIBFILE
echo Built $LIBFILE
#g++ -shared -static -static-libgcc -Iinclude -I$JAVA_HOME/include \
# -I$JAVA_HOME/include/linux src/*.cpp \
# -o lib/freenet/support/CPUInformation/libjcpuid-x86-linux.so
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class freenet_support_CPUInformation_CPUID */
#ifndef _Included_freenet_support_CPUInformation_CPUID
#define _Included_freenet_support_CPUInformation_CPUID
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: freenet_support_CPUInformation_CPUID
* Method: doCPUID
* Signature: (I)Lfreenet/support/CPUInformation/CPUID$CPUIDResult;
*/
JNIEXPORT jobject JNICALL Java_freenet_support_CPUInformation_CPUID_doCPUID
(JNIEnv *, jclass, jint);
#ifdef __cplusplus
}
#endif
#endif
You will need to rename the 'cpuinformation' par of the output folder '..\lib\freenet\support\cpuinformation' to 'CPUInformation' before importing the files to a .jar.
Unfortunately MSVC doesn't respect the casing of the entered output folder.
\ No newline at end of file
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jcpuid", "jcpuid.vcproj", "{161B6AD9-3825-4BA5-893D-D90B09846849}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
EndGlobalSection
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{161B6AD9-3825-4BA5-893D-D90B09846849}.Debug.ActiveCfg = Debug|Win32
{161B6AD9-3825-4BA5-893D-D90B09846849}.Debug.Build.0 = Debug|Win32
{161B6AD9-3825-4BA5-893D-D90B09846849}.Release.ActiveCfg = Release|Win32
{161B6AD9-3825-4BA5-893D-D90B09846849}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal
File added
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="jcpuid"
ProjectGUID="{161B6AD9-3825-4BA5-893D-D90B09846849}"
RootNamespace="jcpuid"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="..\lib\freenet\support\CPUInformation"
IntermediateDirectory="Debug"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;jcpuid_EXPORTS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/jcpuid-x86-windows.dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/jcpuid.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/jcpuid.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="..\lib\freenet\support\CPUInformation"
IntermediateDirectory="Release"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\..\include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;jcpuid_EXPORTS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/jcpuid-x86-windows.dll"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/jcpuid.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath="..\src\jcpuid.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath="..\include\jcpuid.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
#include "jcpuid.h"
//Executes the indicated subfunction of the CPUID operation
JNIEXPORT jobject JNICALL Java_freenet_support_CPUInformation_CPUID_doCPUID
(JNIEnv * env, jclass cls, jint iFunction)
{
int a,b,c,d;
jclass clsResult = env->FindClass ("freenet/support/CPUInformation/CPUID$CPUIDResult");
jmethodID constructor = env->GetMethodID(clsResult,"<init>","(IIII)V" );
#ifdef _MSC_VER
//Use MSVC assembler notation
_asm
{
mov eax, iFunction
cpuid
mov a, eax
mov b, ebx
mov c, ecx
mov d, edx
}
#else
//Use GCC assembler notation
asm
(
"cpuid"
: "=a" (a),
"=b" (b),
"=c"(c),
"=d"(d)
:"a"(iFunction)
);
#endif
return env->NewObject(clsResult,constructor,a,b,c,d);
}
/*
* Created on Jul 17, 2004
*
*/
package freenet.support.CPUInformation;
/**
* @author Iakin
* An interface for classes that provide lowlevel information about AMD CPU's
*
* free (adj.): unencumbered; not under the control of others
* Written by Iakin in 2004 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*/
public interface AMDCPUInfo extends CPUInfo {
/**
* @return true iff the CPU present in the machine is at least an 'k6' CPU
*/
public boolean IsK6Compatible();
/**
* @return true iff the CPU present in the machine is at least an 'k6-2' CPU
*/
public boolean IsK6_2_Compatible();
/**
* @return true iff the CPU present in the machine is at least an 'k6-3' CPU
*/
public boolean IsK6_3_Compatible();
/**
* @return true iff the CPU present in the machine is at least an 'k7' CPU (Atlhon, Duron etc. and better)
*/
public boolean IsAthlonCompatible();
/**
* @return true iff the CPU present in the machine is at least an 'k8' CPU (Atlhon 64, Opteron etc. and better)
*/
public boolean IsAthlon64Compatible();
}
This diff is collapsed.
/*
* Created on Jul 16, 2004
*
*/
package freenet.support.CPUInformation;
/**
* @author Iakin
* An interface for classes that provide lowlevel information about CPU's
*
* free (adj.): unencumbered; not under the control of others
* Written by Iakin in 2004 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*/
public interface CPUInfo
{
/**
* @return A string indicating the vendor of the CPU.
*/
public String getVendor();
/**
* @return A string detailing what type of CPU that is present in the machine. I.e. 'Pentium IV' etc.
* @throws UnknownCPUException If for any reson the retrieval of the requested information
* failed. The message encapsulated in the execption indicates the
* cause of the failure.
*/
public String getCPUModelString() throws UnknownCPUException;
/**
* @return true iff the CPU support the MMX instruction set.
*/
public boolean hasMMX();
/**
* @return true iff the CPU support the SSE instruction set.
*/
public boolean hasSSE();
/**
* @return true iff the CPU support the SSE2 instruction set.
*/
public boolean hasSSE2();
}
/*
* Created on Jul 17, 2004
*
*/
package freenet.support.CPUInformation;
/**
* @author Iakin
* An interface for classes that provide lowlevel information about Intel CPU's
*
* free (adj.): unencumbered; not under the control of others
* Written by Iakin in 2004 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*/
public interface IntelCPUInfo extends CPUInfo {
/**
* @return true iff the CPU is at least a Pentium CPU.
*/
public boolean IsPentiumCompatible();
/**
* @return true iff the CPU is at least a Pentium which implements the MMX instruction/feature set.
*/
public boolean IsPentiumMMXCompatible();
/**
* @return true iff the CPU implements at least the p6 instruction set (Pentium II or better).
* Please note that an PentimPro CPU causes/should cause this method to return false (due to that CPU using a
* very early implementation of the p6 instruction set. No MMX etc.)
*/
public boolean IsPentium2Compatible();
/**
* @return true iff the CPU implements at least a Pentium III level of the p6 instruction/feature set.
*/
public boolean IsPentium3Compatible();
/**
* @return true iff the CPU implements at least a Pentium IV level instruction/feature set.
*/
public boolean IsPentium4Compatible();
}
/*
* Created on Jul 16, 2004
*/
package freenet.support.CPUInformation;
/**
* @author Iakin
*
*/
public class UnknownCPUException extends RuntimeException {
public UnknownCPUException() {
super();
}
public UnknownCPUException(String message) {
super(message);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment