public Level(int length, int height) { // ints = new Vector(); // booleans = new Vector(); this.length = length; this.height = height; xExit = 50; yExit = 10; // System.out.println("Java: Level: lots of news here..."); // System.out.println("length = " + length); // System.out.println("height = " + height); try { map = new byte[length][height]; // System.out.println("map = " + map); data = new byte[length][height]; // System.out.println("data = " + data); spriteTemplates = new SpriteTemplate[length][height]; marioTrace = new int[length][height + 1]; } catch (OutOfMemoryError e) { System.err.println("Java: MarioAI MEMORY EXCEPTION: OutOfMemory exception. Exiting..."); e.printStackTrace(); System.exit(-3); } // System.out.println("spriteTemplates = " + spriteTemplates); // observation = new byte[length][height]; // System.out.println("observation = " + observation); }
public static void main(String[] args) { byte[] T, U, V; int[] A; int i, j, n, pidx; long start, finish; for (i = 0; i < args.length; ++i) { System.out.print(args[i] + ": "); try { /* Open a file for reading. */ File f = new File(args[i]); FileInputStream s = new FileInputStream(f); n = (int) f.length(); System.out.print(n + " bytes ... "); /* Allocate 5n bytes of memory. */ T = new byte[n]; U = new byte[n]; V = new byte[n]; A = new int[n]; /* Read n bytes of data. */ s.read(T); s.close(); s = null; f = null; /* Construct the suffix array. */ start = new Date().getTime(); pidx = new sais().bwtransform(T, U, A, n); finish = new Date().getTime(); System.out.println(((finish - start) / 1000.0) + " sec"); System.out.print("unbwtcheck ... "); unbwt(U, V, A, n, pidx); for (j = 0; j < n; ++j) { if (T[j] != V[j]) { System.err.println("error " + j + ": " + T[j] + ", " + V[j]); return; } } System.err.println("Done."); T = null; U = null; V = null; A = null; } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } } }
void readFrom(ObjectInputStream in) throws Exception { wordClasses = (WordClass[]) in.readObject(); wordClassMap = (Map) in.readObject(); skipHeader = (int[]) in.readObject(); values = (AttributeValue[]) in.readObject(); interpretationCountBits = in.readInt(); interpretationLengthBits = in.readInt(); valueCountBits = in.readInt(); valuePointerBits = in.readInt(); wordClassBits = in.readInt(); wordClassCount = in.readInt(); maxFreeValueCount = in.readInt(); int entryCount = in.readInt(); entries = new DictionaryEntry[entryCount]; hashCodes = new int[entryCount]; Runtime rt = Runtime.getRuntime(); int i = 0; try { UNKNOWN = DictionaryEntry.readDictionaryEntryFrom(in); UNKNOWN_WORD_UPPER = DictionaryEntry.readDictionaryEntryFrom(in); UNKNOWN_WORD_LOWER = DictionaryEntry.readDictionaryEntryFrom(in); CHAR = DictionaryEntry.readDictionaryEntryFrom(in); NUMBER = DictionaryEntry.readDictionaryEntryFrom(in); for (i = 0; i < entryCount; i++) { hashCodes[i] = in.readInt(); entries[i] = DictionaryEntry.readDictionaryEntryFrom(in); } } catch (OutOfMemoryError oem) { oem.printStackTrace(); throw new Exception(oem.getMessage()); } interpreterPool = new Stack(); tokenizedInputExtensionPool = new Stack(); checkBuild(); }
private void handleException(Realm realm, OutOfMemoryError e) { // Try to recover after OOM. Runtime rt = Runtime.getRuntime(); long beforeGc = rt.freeMemory(); rt.gc(); long afterGc = rt.freeMemory(); if (afterGc > beforeGc && (afterGc - beforeGc) < 50_000_000) { // Calling gc() cleared less than 50MB, assume unrecoverable OOM and rethrow error. throw e; } // Create script exception with stacktrace from oom-error. ScriptException exception = newInternalError(realm.defaultContext(), Messages.Key.OutOfMemoryVM); exception.setStackTrace(e.getStackTrace()); handleException(realm, exception); }