JVM test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lynxeyed_atsu
Date:
Thu Aug 29 13:31:23 2013 +0000
Parent:
6:b9d0d96b052f
Child:
8:d9e205196dfc
Commit message:
fixed memory pool manager to re-use freed memory

Changed in this revision

device_depend.cpp Show annotated file Show diff for this revision Revisions of this file
device_depend.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
pool.cpp Show annotated file Show diff for this revision Revisions of this file
pool.h Show annotated file Show diff for this revision Revisions of this file
ravem.h Show annotated file Show diff for this revision Revisions of this file
--- a/device_depend.cpp	Mon Aug 26 15:02:07 2013 +0000
+++ b/device_depend.cpp	Thu Aug 29 13:31:23 2013 +0000
@@ -37,6 +37,7 @@
 
 void port_write(int port, int bit, int value){
 	//bit = value;
+	return;
 }
 
 void bytecode_read_init(void){
--- a/device_depend.h	Mon Aug 26 15:02:07 2013 +0000
+++ b/device_depend.h	Thu Aug 29 13:31:23 2013 +0000
@@ -3,7 +3,6 @@
 
 #include "mbed.h"
 
-
 // functions
 void hardware_init(void);
 void uart_init(int baud_rate);
--- a/main.cpp	Mon Aug 26 15:02:07 2013 +0000
+++ b/main.cpp	Thu Aug 29 13:31:23 2013 +0000
@@ -1,4 +1,3 @@
-
 #include <stdio.h>
 #include <string.h>
 
--- a/pool.cpp	Mon Aug 26 15:02:07 2013 +0000
+++ b/pool.cpp	Thu Aug 29 13:31:23 2013 +0000
@@ -5,6 +5,36 @@
 int pl_buf[pool_size];
 pool_all poal;
 
+
+int *pool_memmove(int size){
+    int *pointr;
+    pool_each poeh;
+    size = (size + (sizeof(int) - 1)) / sizeof(int); //round int type alignment
+    poal.first_pointer = &pl_buf[0];
+    
+    //seek pool_each header
+    pointr = poal.first_pointer + (int)((sizeof(pool_all) + (sizeof(int) - 1)) / sizeof(int));
+    
+    //todo: add magic number
+    while(1){
+        memcpy(&poeh, pointr, sizeof(pool_each));
+        if((poeh.my_size == 0)||(pointr >= poal.next_pointer)){return NULL;}
+        
+        if(poeh.available == memory_invalid){
+            if(size <= poeh.my_size){
+                // seek data_header
+                poeh.available = memory_available;
+                memcpy(pointr, &poeh, sizeof(pool_each));
+                
+                pointr = pointr + (int)((sizeof(pool_each) + (sizeof(int) - 1)) / sizeof(int));
+                return pointr;
+            }
+        }
+        pointr = pointr + (int)((sizeof(pool_each) + (sizeof(int) - 1)) / sizeof(int)) + poeh.my_size;
+    }
+    
+    
+}
 void pool_init(void){    
     poal.first_pointer = &pl_buf[0];
     poal.pool_size_all = pool_size;
@@ -16,12 +46,12 @@
 }
 
 int *pool_alloc(int size){
+    pool_each poeh;
+    int *pointr;
     
+    if(NULL != (pointr = pool_memmove(size)))return pointr;  
     size = (size + (sizeof(int) - 1)) / sizeof(int); //round int type alignment
-        
-    int *pointr;
-    pool_each poeh;
-    
+
     poal.pool_size_all = poal.pool_size_all - ((sizeof(pool_each) + (sizeof(int) - 1)) / sizeof(int)) - size; // int alignment
     
     if(poal.pool_size_all <= 0){
--- a/pool.h	Mon Aug 26 15:02:07 2013 +0000
+++ b/pool.h	Thu Aug 29 13:31:23 2013 +0000
@@ -42,7 +42,5 @@
 int *pool_alloc(int size);
 int *pool_realloc(int *pointr, int size);
 
-
-
 #endif
 
--- a/ravem.h	Mon Aug 26 15:02:07 2013 +0000
+++ b/ravem.h	Thu Aug 29 13:31:23 2013 +0000
@@ -103,7 +103,6 @@
 
 #define JAVA_new					0xbb					// 2
 
-
 typedef struct {
 	int		tag;
 	int		index;
@@ -159,7 +158,5 @@
 
 class_st decodeVM(class_st cl);
 
-
-
 #endif /* RAVEM_H_ */