1 /* Copyright (C) 2008, Arthur Benilov 2 3 This program is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public License 5 as published by the Free Software Foundation; either version 2 6 of the License, or (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 16 USA. 17 */ 18 19 #include <stdio.h> 20 #include <stdlib.h> 21 22 #include "assert.h" 23 #include "types.h" 24 #include "alloc.h" 25 #include "utf8.h" 26 #include "class.h" 27 #include "heap.h" 28 #include "class.h" 29 #include "method.h" 30 #include "loader.h" 31 #include "exec.h" 32 #include "thread.h" 33 #include "gc.h" 34 35 /* ------------------------------------------------------ */ 36 37 void jvm_start ( ) { 38 class_t *bootstrap; 39 heap_t *heap; 40 41 /* Initialize system memory allocator 42 */ 43 jvm_alloc_init(); 44 45 /* We pass the stack and heap sized here. 46 * The heap will be shared among all the child threads. 47 * However, the stack will be recreated (of the same size) 48 * for each new thread 49 */ 50 java_thread_init(64 * 1024, 32 * 1024); 51 52 /* JIT compiler initialization. We have to do this _after_ java_thread_init() 53 * in order to have an execution environment ready. 54 */ 55 jit_opcode_init(); 56 57 /* Here we can specify either a jar archive or 58 * a folder with java classes like 59 * loader_init("classpath/done"); 60 */ 61 loader_init("classpath.jar"); 62 /* loader_init("./classpath/done"); */ 63 64 /* Application entry point is in sys/entry/Entry 65 * class, methos entry(). This method should be static. 66 */ 67 bootstrap = class_resolve("sys/entry/Entry"); 68 69 if ( bootstrap ) { 70 method_t *entry = method_resolve(bootstrap, utf8_hash("entry") ^ utf8_hash("()V")); 71 72 if ( entry ) { 73 if ( entry->access_flags & ACC_STATIC ) { 74 long long start_time = getTimeInMs(); 75 long long finish_time; 76 method_invoke(bootstrap, NULL, entry); 77 finish_time = getTimeInMs(); 78 printf("Program run: %d ms\n", finish_time - start_time); 79 80 /* Normally, the application ends here and so do 81 * all created threads. In the embedded environment, however, 82 * the java threads may continue to run. So, we do not 83 * release the allocated resources here. 84 * It is recommended that java embedded application is 85 * designed in such way, that method entry() never 86 * returns. 87 */ 88 } else { 89 PANIC("Method sys/entry/Entry.entry() must be static\n"); 90 } 91 } else { 92 PANIC("Method sys/entry/Entry.entry() was not found\n"); 93 } 94 } else { 95 PANIC("sys/entry/Entry class cannot be resolved\n"); 96 } 97 98 /* Release all memory that was allocated. 99 * Once it is done, no pointer is valid in the JVM. 100 * Application must be terminated. 101 */ 102 jvm_memory_cleanup(); 103 } 104 105 /* ------------------------------------------------------ */ 106 107 #ifndef VXWORKS 108 int main ( int argc, char **argv ) { 109 110 jvm_start(); 111 112 return 0; 113 } 114 #endif 115 116 /* ------------------------------------------------------ */ 117 /* End of file */ 118