System: add identityHashCode
This commit is contained in:
parent
8036060321
commit
00e505b667
15
c/native.c
15
c/native.c
@ -10,6 +10,7 @@
|
||||
#include "native/object.h"
|
||||
#include "native/printstream.h"
|
||||
#include "native/runtime.h"
|
||||
#include "native/system.h"
|
||||
|
||||
typedef void (* native_func_t)(struct vm * vm, uint32_t * args);
|
||||
|
||||
@ -126,15 +127,9 @@ const static struct native_method native_method[] = {
|
||||
{
|
||||
.class_name = "java/lang/Object",
|
||||
.method_name = "_getClass",
|
||||
.method_descriptor = "()Ljava/lang/Class;",
|
||||
.method_descriptor = "(Ljava/lang/Object;)Ljava/lang/Class;",
|
||||
.func = native_java_lang_object_getclass_1,
|
||||
},
|
||||
{
|
||||
.class_name = "java/lang/Object",
|
||||
.method_name = "_hashCode",
|
||||
.method_descriptor = "()I",
|
||||
.func = native_java_lang_object_hashcode_1,
|
||||
},
|
||||
{
|
||||
.class_name = "java/lang/Runtime",
|
||||
.method_name = "_freeMemory",
|
||||
@ -153,6 +148,12 @@ const static struct native_method native_method[] = {
|
||||
.method_descriptor = "()I",
|
||||
.func = native_java_lang_runtime_totalmemory_0,
|
||||
},
|
||||
{
|
||||
.class_name = "java/lang/System",
|
||||
.method_name = "_hashCode",
|
||||
.method_descriptor = "(Ljava/lang/Object;)I",
|
||||
.func = native_java_lang_system_hashcode_1,
|
||||
},
|
||||
};
|
||||
|
||||
struct hash_table_entry * native_init_hash_table(int * hash_table_length)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "object.h"
|
||||
#include "printf.h"
|
||||
#include "vm_instance.h"
|
||||
|
||||
void native_java_lang_object_getclass_1(struct vm * vm, uint32_t * args)
|
||||
@ -15,9 +14,3 @@ void native_java_lang_object_getclass_1(struct vm * vm, uint32_t * args)
|
||||
|
||||
operand_stack_push_ref(vm->current_frame, class_objectref);
|
||||
}
|
||||
|
||||
void native_java_lang_object_hashcode_1(struct vm * vm, uint32_t * args)
|
||||
{
|
||||
struct objectref * objectref = (struct objectref *)args[0];
|
||||
operand_stack_push_u32(vm->current_frame, (uint32_t)objectref); // objectref as integer
|
||||
}
|
||||
|
@ -5,5 +5,3 @@
|
||||
#include "frame.h"
|
||||
|
||||
void native_java_lang_object_getclass_1(struct vm * vm, uint32_t * args);
|
||||
|
||||
void native_java_lang_object_hashcode_1(struct vm * vm, uint32_t * args);
|
||||
|
7
c/native/system.c
Normal file
7
c/native/system.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include "system.h"
|
||||
|
||||
void native_java_lang_system_hashcode_1(struct vm * vm, uint32_t * args)
|
||||
{
|
||||
struct objectref * objectref = (struct objectref *)args[0];
|
||||
operand_stack_push_u32(vm->current_frame, (uint32_t)objectref); // objectref as integer
|
||||
}
|
7
c/native/system.h
Normal file
7
c/native/system.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "frame.h"
|
||||
|
||||
void native_java_lang_system_hashcode_1(struct vm * vm, uint32_t * args);
|
@ -12,16 +12,14 @@ public class Object {
|
||||
return this == obj;
|
||||
}
|
||||
|
||||
private final native Class<?> _getClass();
|
||||
private final native static Class<?> _getClass(Object o);
|
||||
|
||||
public final Class<?> getClass() {
|
||||
return _getClass();
|
||||
return _getClass(this);
|
||||
}
|
||||
|
||||
private native int _hashCode();
|
||||
|
||||
public int hashCode() {
|
||||
return _hashCode();
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -3,11 +3,23 @@ package java.lang;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public final class System {
|
||||
public static PrintStream out = null;
|
||||
public static PrintStream err;
|
||||
public static PrintStream out;
|
||||
|
||||
private System() {
|
||||
}
|
||||
static {
|
||||
out = new PrintStream();
|
||||
err = new PrintStream();
|
||||
}
|
||||
|
||||
public static void gc() {
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
|
||||
private final native static int _hashCode(Object x);
|
||||
|
||||
public static int identityHashCode(Object x) {
|
||||
return _hashCode(x);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user