Skip to content

Commit

Permalink
Added JVM_IHashCode.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed May 30, 2024
1 parent e43f3f4 commit 376cf8a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/IKVM.Runtime/LibJVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ unsafe struct JVMInvokeInterface
public nint JVM_ThrowException;
public nint JVM_GetThreadInterruptEvent;
public nint JVM_ActiveProcessorCount;
public nint JVM_IHashCode;

}

Expand All @@ -50,6 +51,9 @@ unsafe struct JVMInvokeInterface
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int JVM_ActiveProcessorCountDelegate();

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int JVM_IHashCodeDelegate(JNIEnv* env, nint handle);

delegate void JVM_InitDelegate(JVMInvokeInterface* iface);

delegate nint JVM_LoadLibraryDelegate([MarshalAs(UnmanagedType.LPUTF8Str)] string name);
Expand Down Expand Up @@ -77,6 +81,7 @@ unsafe struct JVMInvokeInterface
readonly JVM_ThrowExceptionDelegate _JVM_ThrowException;
readonly JVM_GetThreadInterruptEventDelegate _JVM_GetThreadInterruptEvent;
readonly JVM_ActiveProcessorCountDelegate _JVM_ActiveProcessorCount;
readonly JVM_IHashCodeDelegate _JVM_IHashCode;

/// <summary>
/// Initializes a new instance.
Expand All @@ -101,6 +106,7 @@ unsafe struct JVMInvokeInterface
jvmii->JVM_ThrowException = Marshal.GetFunctionPointerForDelegate(_JVM_ThrowException = JVM_ThrowException);
jvmii->JVM_GetThreadInterruptEvent = Marshal.GetFunctionPointerForDelegate(_JVM_GetThreadInterruptEvent = JVM_GetThreadInterruptEvent);
jvmii->JVM_ActiveProcessorCount = Marshal.GetFunctionPointerForDelegate(_JVM_ActiveProcessorCount = JVM_ActiveProcessorCount);
jvmii->JVM_IHashCode = Marshal.GetFunctionPointerForDelegate(_JVM_IHashCode = JVM_IHashCode);
_JVM_Init(jvmii);
}

Expand Down Expand Up @@ -183,6 +189,17 @@ int JVM_ActiveProcessorCount()
return Environment.ProcessorCount;
}

/// <summary>
/// Invoked by the native code to get the hashcode of an object.
/// </summary>
/// <param name="env"></param>
/// <param name="handle"></param>
/// <returns></returns>
int JVM_IHashCode(JNIEnv* env, nint handle)
{
return handle == 0 ? 0 : env->UnwrapRef(handle).GetHashCode();
}

/// <summary>
/// Invokes the 'JVM_LoadLibrary' method from libjvm.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/libjvm/ikvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ typedef struct JVMInvokeInterface {
void (*JVM_ThrowException)(const char*, const char*);
void* (*JVM_GetThreadInterruptEvent)();
jint (*JVM_ActiveProcessorCount)();
jint (*JVM_IHashCode)(JNIEnv *pEnv, jobject handle);
} JVMInvokeInterface;

extern JVMInvokeInterface *jvmii;

JNIEXPORT void JNICALL JVM_Init(JVMInvokeInterface *p_jvmii);

void JNICALL JVM_ThrowException(const char *name, const char *msg);
JNIEXPORT void JNICALL JVM_ThrowException(const char *name, const char *msg);

#ifdef __cplusplus
}
Expand Down
50 changes: 44 additions & 6 deletions src/libjvm/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,18 @@ jlong JNICALL JVM_NanoTime(JNIEnv* env, jclass ignored)

void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length)
{

JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_ArrayCopy");
}

jobject JNICALL JVM_InitProperties(JNIEnv* env, jobject properties)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_InitProperties");
return 0;
}

jstring JNICALL JVM_GetTemporaryDirectory(JNIEnv* env)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetTemporaryDirectory");
return 0;
}

Expand Down Expand Up @@ -278,174 +280,203 @@ jint JNICALL JVM_ActiveProcessorCount() {

jclass JNICALL JVM_FindClassFromClass(JNIEnv* env, const char* name, jboolean init, jclass from)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_FindClassFromClass");
return 0;
}

jclass JNICALL JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_FindClassFromClassLoader");
return 0;
}

jboolean JNICALL JVM_IsInterface(JNIEnv* env, jclass cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_IsInterface");
return 0;
}

const char* JNICALL JVM_GetClassNameUTF(JNIEnv* env, jclass cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetClassNameUTF");
return 0;
}

void JNICALL JVM_GetClassCPTypes(JNIEnv* env, jclass cls, unsigned char* types)
{

JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetClassCPTypes");
}

jint JNICALL JVM_GetClassCPEntriesCount(JNIEnv* env, jclass cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetClassCPEntriesCount");
return 0;
}

jint JNICALL JVM_GetClassFieldsCount(JNIEnv* env, jclass cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetClassFieldsCount");
return 0;
}


jint JNICALL JVM_GetClassMethodsCount(JNIEnv* env, jclass cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetClassMethodsCount");
return 0;
}

void JNICALL JVM_GetMethodIxExceptionIndexes(JNIEnv* env, jclass cls, jint method_index, unsigned short* exceptions)
{

JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxExceptionIndexes");
}

jint JNICALL JVM_GetMethodIxExceptionsCount(JNIEnv* env, jclass cls, jint method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxExceptionsCount");
return 0;
}

void JNICALL JVM_GetMethodIxByteCode(JNIEnv* env, jclass cls, jint method_index, unsigned char* code)
{

JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxByteCode");
}

jint JNICALL JVM_GetMethodIxByteCodeLength(JNIEnv* env, jclass cls, jint method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxByteCodeLength");
return 0;
}

void JNICALL JVM_GetMethodIxExceptionTableEntry(JNIEnv* env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType* entry)
{

JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxExceptionTableEntry");
}

jint JNICALL JVM_GetMethodIxExceptionTableLength(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxExceptionTableLength");
return 0;
}

jint JNICALL JVM_GetMethodIxModifiers(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxModifiers");
return 0;
}

jint JNICALL JVM_GetFieldIxModifiers(JNIEnv* env, jclass cls, int field_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetFieldIxModifiers");
return 0;
}

jint JNICALL JVM_GetMethodIxLocalsCount(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxLocalsCount");
return 0;
}

jint JNICALL JVM_GetMethodIxArgsSize(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxArgsSize");
return 0;
}

jint JNICALL JVM_GetMethodIxMaxStack(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxMaxStack");
return 0;
}

jboolean JNICALL JVM_IsConstructorIx(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_IsConstructorIx");
return 0;
}

jboolean JNICALL JVM_IsVMGeneratedMethodIx(JNIEnv* env, jclass cls, int method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_IsVMGeneratedMethodIx");
return 0;
}

const char* JNICALL JVM_GetMethodIxNameUTF(JNIEnv* env, jclass cls, jint method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxNameUTF");
return 0;
}

const char* JVM_GetMethodIxSignatureUTF(JNIEnv* env, jclass cls, jint method_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetMethodIxSignatureUTF");
return 0;
}

const char* JNICALL JVM_GetCPMethodNameUTF(JNIEnv* env, jclass cls, jint cp_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPMethodNameUTF");
return 0;
}

const char* JNICALL JVM_GetCPMethodSignatureUTF(JNIEnv* env, jclass cls, jint cp_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPMethodSignatureUTF");
return 0;
}

const char* JNICALL JVM_GetCPFieldSignatureUTF(JNIEnv* env, jclass cls, jint cp_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPFieldSignatureUTF");
return 0;
}

const char* JNICALL JVM_GetCPClassNameUTF(JNIEnv* env, jclass cls, jint cp_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPClassNameUTF");
return 0;
}

const char* JNICALL JVM_GetCPFieldClassNameUTF(JNIEnv* env, jclass cls, jint cp_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPFieldClassNameUTF");
return 0;
}

const char* JNICALL JVM_GetCPMethodClassNameUTF(JNIEnv* env, jclass cls, jint cp_index)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPMethodClassNameUTF");
return 0;
}

jint JNICALL JVM_GetCPFieldModifiers(JNIEnv* env, jclass cls, int cp_index, jclass called_cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPFieldModifiers");
return 0;
}

jint JVM_GetCPMethodModifiers(JNIEnv* env, jclass cls, int cp_index, jclass called_cls)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_GetCPMethodModifiers");
return 0;
}

void JNICALL JVM_ReleaseUTF(const char* utf)
{

JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_ReleaseUTF");
}

jboolean JNICALL JVM_IsSameClassPackage(JNIEnv* env, jclass class1, jclass class2)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_IsSameClassPackage");
return 0;
}

// Networking library support ////////////////////////////////////////////////////////////////////

jint JNICALL JVM_InitializeSocketLibrary()
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_InitializeSocketLibrary");
return 0;
}

Expand Down Expand Up @@ -1016,14 +1047,21 @@ void* JNICALL JVM_GetThreadInterruptEvent()

void* JNICALL JVM_RegisterSignal(jint sig, void* handler)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_RegisterSignal");
return 0;
}

jboolean JNICALL JVM_RaiseSignal(jint sig)
{
JVM_ThrowException("java/lang/InternalError", "Unsupported JVM method: JVM_RaiseSignal");
return JNI_FALSE;
}

jint JNICALL JVM_IHashCode(JNIEnv *pEnv, jobject handle)
{
return jvmii->JVM_IHashCode(pEnv, handle);
}

int jio_vsnprintf(char* str, size_t count, const char* fmt, va_list args)
{
// Reject count values that are negative signed values converted to
Expand Down
2 changes: 1 addition & 1 deletion src/libjvm/mapfile-vers-product
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
#_JVM_GetVersionInfo
#_JVM_Halt
#_JVM_HoldsLock
#_JVM_IHashCode
_JVM_IHashCode
#_JVM_InitAgentProperties
_JVM_InitProperties
#_JVM_InitializeCompiler
Expand Down

0 comments on commit 376cf8a

Please sign in to comment.