CLDC 8: add java.lang.Runtime
This commit is contained in:
parent
27584e8aa2
commit
bb128578f0
@ -142,6 +142,21 @@ void memory_iterate_allocated(memory_iterate_func_t func)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t memory_count_free_memory()
|
||||||
|
{
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < free_list_length; i++) {
|
||||||
|
if (free_list[i] == 0)
|
||||||
|
sum += 1;
|
||||||
|
}
|
||||||
|
return sum * block_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t memory_count_total_memory()
|
||||||
|
{
|
||||||
|
return (sizeof (memory));
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -8,3 +8,5 @@ void memory_free(void * p);
|
|||||||
bool memory_is_allocated(void * p);
|
bool memory_is_allocated(void * p);
|
||||||
typedef void (* memory_iterate_func_t)(void * address);
|
typedef void (* memory_iterate_func_t)(void * address);
|
||||||
void memory_iterate_allocated(memory_iterate_func_t func);
|
void memory_iterate_allocated(memory_iterate_func_t func);
|
||||||
|
int32_t memory_count_free_memory();
|
||||||
|
int32_t memory_count_total_memory();
|
||||||
|
19
c/native.c
19
c/native.c
@ -9,6 +9,7 @@
|
|||||||
#include "native/memory.h"
|
#include "native/memory.h"
|
||||||
#include "native/object.h"
|
#include "native/object.h"
|
||||||
#include "native/printstream.h"
|
#include "native/printstream.h"
|
||||||
|
#include "native/runtime.h"
|
||||||
|
|
||||||
typedef void (* native_func_t)(struct vm * vm, uint32_t * args);
|
typedef void (* native_func_t)(struct vm * vm, uint32_t * args);
|
||||||
|
|
||||||
@ -134,6 +135,24 @@ const static struct native_method native_method[] = {
|
|||||||
.method_descriptor = "()I",
|
.method_descriptor = "()I",
|
||||||
.func = native_java_lang_object_hashcode_1,
|
.func = native_java_lang_object_hashcode_1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.class_name = "java/lang/Runtime",
|
||||||
|
.method_name = "_freeMemory",
|
||||||
|
.method_descriptor = "()I",
|
||||||
|
.func = native_java_lang_runtime_freememory_0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.class_name = "java/lang/Runtime",
|
||||||
|
.method_name = "_gc",
|
||||||
|
.method_descriptor = "()V",
|
||||||
|
.func = native_java_lang_runtime_gc_0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.class_name = "java/lang/Runtime",
|
||||||
|
.method_name = "_totalMemory",
|
||||||
|
.method_descriptor = "()I",
|
||||||
|
.func = native_java_lang_runtime_totalmemory_0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hash_table_entry * native_init_hash_table(int * hash_table_length)
|
struct hash_table_entry * native_init_hash_table(int * hash_table_length)
|
||||||
|
20
c/native/runtime.c
Normal file
20
c/native/runtime.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "runtime.h"
|
||||||
|
#include "memory_allocator.h"
|
||||||
|
#include "gc.h"
|
||||||
|
|
||||||
|
void native_java_lang_runtime_freememory_0(struct vm * vm, uint32_t * args)
|
||||||
|
{
|
||||||
|
int32_t count = memory_count_free_memory();
|
||||||
|
operand_stack_push_u32(vm->current_frame, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void native_java_lang_runtime_gc_0(struct vm * vm, uint32_t * args)
|
||||||
|
{
|
||||||
|
gc_run(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void native_java_lang_runtime_totalmemory_0(struct vm * vm, uint32_t * args)
|
||||||
|
{
|
||||||
|
int32_t count = memory_count_total_memory();
|
||||||
|
operand_stack_push_u32(vm->current_frame, count);
|
||||||
|
}
|
9
c/native/runtime.h
Normal file
9
c/native/runtime.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "frame.h"
|
||||||
|
|
||||||
|
void native_java_lang_runtime_freememory_0(struct vm * vm, uint32_t * args);
|
||||||
|
void native_java_lang_runtime_gc_0(struct vm * vm, uint32_t * args);
|
||||||
|
void native_java_lang_runtime_totalmemory_0(struct vm * vm, uint32_t * args);
|
@ -2,7 +2,6 @@ package java.lang;
|
|||||||
|
|
||||||
import java.lang.DecimalDigits;
|
import java.lang.DecimalDigits;
|
||||||
|
|
||||||
|
|
||||||
public final class Integer
|
public final class Integer
|
||||||
extends Number
|
extends Number
|
||||||
implements Comparable<Integer> {
|
implements Comparable<Integer> {
|
||||||
|
@ -2,7 +2,17 @@ package java.lang;
|
|||||||
|
|
||||||
import java.lang.DecimalDigits;
|
import java.lang.DecimalDigits;
|
||||||
|
|
||||||
public class Long {
|
|
||||||
|
public final class Long
|
||||||
|
// extends Number
|
||||||
|
// implements Comparable<Long> {
|
||||||
|
{
|
||||||
|
public static final long MAX_VALUE = 9223372036854775807L;
|
||||||
|
|
||||||
|
public static final long MIN_VALUE = -9223372036854775808L;
|
||||||
|
|
||||||
|
public static final int SIZE = 64;
|
||||||
|
|
||||||
public static int stringSize(long n) {
|
public static int stringSize(long n) {
|
||||||
int sign_digits = 0;
|
int sign_digits = 0;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
38
classes/java/lang/Runtime.java
Normal file
38
classes/java/lang/Runtime.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package java.lang;
|
||||||
|
|
||||||
|
public class Runtime {
|
||||||
|
private static final Runtime runtime;
|
||||||
|
|
||||||
|
private Runtime() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
runtime = new Runtime();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native int _freeMemory();
|
||||||
|
|
||||||
|
public long freeMemory() {
|
||||||
|
return _freeMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native void _gc();
|
||||||
|
|
||||||
|
public void gc() {
|
||||||
|
_gc();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Runtime getRuntime() {
|
||||||
|
return runtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long maxMemory() {
|
||||||
|
return Long.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native int _totalMemory();
|
||||||
|
|
||||||
|
public long totalMemory() {
|
||||||
|
return _totalMemory();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user