void deque_push_back(Item n) { assert(!deque_full()); if (deque_empty()) { set_init_state(); } content[tail] = n; tail = (tail + 1) % MAX; count++; }
/** * Perform a return from a method call. Clean up the stack, setup * the return of any results, release any monitor and finally set the * PC for the return address. */ void do_return (int numWords) { StackFrame *stackFrame; STACKWORD *fromStackPtr; stackFrame = current_stackframe(); #if DEBUG_BYTECODE printf ("\n------ return ----- %d ------------------\n\n", stackFrame->methodRecord->signatureId); #endif #if DEBUG_METHODS printf ("do_return: method: %d # num. words: %d\n", stackFrame->methodRecord->signatureId, numWords); #endif #ifdef VERIFY assert (stackFrame != null, LANGUAGE3); #endif if (stackFrame->monitor != null) { // if this was a class init then mark the class as now complete if (stackFrame->methodRecord->signatureId == _6clinit_7_4_5V) set_init_state((ClassRecord *)(stackFrame->monitor), C_INITIALIZED); exit_monitor (currentThread, stackFrame->monitor); } #if DEBUG_THREADS || DEBUG_METHODS printf ("do_return: stack frame array size: %d\n", currentThread->stackFrameIndex); #endif // Place source ptr below data to be copied up the stack fromStackPtr = get_stack_ptr_at_cur(numWords); // Pop stack frame currentThread->stackFrameIndex--; stackFrame--; // Assign registers update_registers (stackFrame); #if DEBUG_METHODS printf ("do_return: stack reset to:\n"); //printf ("-- stack ptr = %d\n", (int) get_stack_ptr()); #endif while (numWords--) { push_word_cur (*(++fromStackPtr)); } }
int main(int argc, char **argv) { struct hist_record rec; char *line; game initgame; bool localdat = false; char cwd_buf[1024]; unsigned int (*bcounts)[3]; int ca[2]; date current = {0, 0, 0}; int arg; int rc; for (arg = 1; arg < argc; arg++) { if (!strcmp(argv[arg], "--localdat")) { localdat=true; } else { fprintf(stderr, "Unrecognised argument '%s'\n", argv[arg]); return 5; } } if(!(cwd=getcwd(cwd_buf, 1024))) { perror("getcwd"); return 5; } fprintf(stderr, "Loading data files...\n"); #ifndef WINDOWS if(chdir(localdat?cwd:DATIDIR)) { perror("Failed to enter data dir: chdir"); if(!localdat) fprintf(stderr, "(Maybe try with --localdat, or make install)\n"); return 5; } #endif rc = load_data(); if (rc) return rc; bcounts = calloc(ntypes, sizeof(*bcounts)); if (!bcounts) { perror("calloc"); return 5; } rc = set_init_state(&initgame); if (rc) return rc; fprintf(stderr, "Data files loaded\n"); while(!feof(stdin)) { line = fgetl(stdin); if (!line) { fprintf(stderr, "Unexpected EOF\n"); return 3; } if (!strncmp(line, "History:", 8)) { free(line); break; } } while(!feof(stdin)) { line = fgetl(stdin); if (!line) break; rc = parse_event(&rec, line); if (rc) { fprintf(stderr, "Error %d in line: %s\n", rc, line); free(line); return rc; } free(line); if (rec.type == HT_INIT) { char savbuf[80]; snprintf(savbuf, 80, "save/%s", rec.init); rc = loadgame(savbuf, &initgame); if (rc) { fprintf(stderr, "Error %d loading INITgame '%s'\n", rc, savbuf); return 6; } for (unsigned int i = 0; i < initgame.nbombers; i++) bcounts[initgame.bombers[i].type][0]++; ca[0] = initgame.cshr; ca[1] = initgame.cash; } else if (rec.type == HT_AC) { if (rec.ac.type == AE_CT) { if (!rec.ac.fighter) { bcounts[rec.ac.ac_type][0]++; bcounts[rec.ac.ac_type][1]++; } } else if (rec.ac.type == AE_CROB) { if (!rec.ac.fighter) { bcounts[rec.ac.ac_type][0]--; bcounts[rec.ac.ac_type][2]++; } } } else if (rec.type == HT_MISC) { if (rec.misc.type == ME_CASH) { ca[0] = rec.misc.cash.delta; ca[1] = rec.misc.cash.current; } } if (diffdate(rec.date, current)) write_counts(current = rec.date, bcounts, ca); } return 0; }
/** * Exceute the static initializer if required. Note that the ret address used * here is set such that the current instruction will be re-started when the * initialization completes. * @return An indication of how the VM should proceed */ int dispatch_static_initializer (ClassRecord *aRec, byte *retAddr) { int state = get_init_state(aRec); ClassRecord *init = aRec; ClassRecord *super = get_class_record(init->parentClass); MethodRecord *method; // Are we needed? if (state & C_INITIALIZED) return EXEC_CONTINUE; // We need to initialize all of the super classes first. So we find the // highest one that has not been initialized and deal with that. This code // will then be called again and we will init the next highest and so on // until all of the classes in the chain are done. for(;;) { // find first super class that has not been initialized while (init != super && (get_init_state(super) & C_INITIALIZED) == 0) { init = super; super = get_class_record(init->parentClass); } // Do we have an initilizer if so we have found our class if (has_clinit (init)) break; // no initializer so mark as now initialized set_init_state (init, C_INITIALIZED); // If we are at the start of the list we are done if (init == aRec) return EXEC_CONTINUE; // Otherwise go do it all again init = aRec; } state = get_init_state(init); // are we already initializing ? if (state & C_INITIALIZING) { // Is it this thread that is doing the init? if (get_sync(init)->threadId == currentThread->threadId) return EXEC_CONTINUE; // No so we must retry the current instruction curPc = retAddr; sleep_thread(1); schedule_request(REQUEST_SWITCH_THREAD); return EXEC_RETRY; } #if DEBUG_METHODS printf ("dispatch_static_initializer: has clinit: %d, %d\n", (int) aRec, (int) retAddr); #endif // Static initializer is always the first method method = get_method_table(init); if ((byte *)method == get_binary_base() || method->signatureId != _6clinit_7_4_5V) { throw_new_exception (JAVA_LANG_NOSUCHMETHODERROR); return EXEC_EXCEPTION; } // Can we run it? if (!dispatch_special (method, retAddr)) return EXEC_RETRY; // Mark for next time set_init_state(init, C_INITIALIZING); // and claim the monitor current_stackframe()->monitor = (Object *)init; enter_monitor (currentThread, (Object *)init); return EXEC_RUN; }