Skip to content

Commit

Permalink
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
* @author enebo
*/
interface IRPersistenceValues {
public static final int VERSION = 1;
public final static int TWO_MEGS = 1024 * 1024 * 2;

// Operands and primitive values can be mixed together
@@ -29,7 +30,7 @@ interface IRPersistenceValues {
public final static byte DOUBLE = (byte) (PRIMITIVE_BASE + 10);
public final static byte FULL = (byte) 255;

public final static int PROLOGUE_LENGTH = 2 * 4; // 2 ints at front
public final static int PROLOGUE_LENGTH = 3 * 4; // 3 raw ints {version, scope_offset, pool_offset}

public final static int NULL_STRING = -1;
}
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/ir/persistence/IRReader.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import org.jruby.ir.operands.LocalVariable;
import org.jruby.parser.StaticScope;
import org.jruby.parser.StaticScopeFactory;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Signature;

import java.io.IOException;
@@ -25,8 +24,14 @@
*
* @author enebo
*/
public class IRReader {
public class IRReader implements IRPersistenceValues {
public static IRScope load(IRManager manager, IRReaderDecoder file) throws IOException {
int version = file.decodeIntRaw();

if (version != VERSION) {
throw new IOException("Trying to read incompatable persistence format (version found: " +
version + ", version expected: " + VERSION);
}
int headersOffset = file.decodeIntRaw();
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("header_offset = " + headersOffset);
int poolOffset = file.decodeIntRaw();
Original file line number Diff line number Diff line change
@@ -33,8 +33,6 @@
* Represents a file which is persisted to storage.
*/
public class IRWriterStream implements IRWriterEncoder, IRPersistenceValues {
private static final int VERSION = 0;

private final Map<IRScope, Integer> scopeInstructionOffsets = new HashMap<>();
// FIXME: Allocate direct and use one per thread?
private final ByteBuffer buf = ByteBuffer.allocate(TWO_MEGS);
@@ -260,6 +258,7 @@ public void startEncoding(IRScope script) {
@Override
public void endEncoding(IRScope script) {
try {
stream.write(ByteBuffer.allocate(4).putInt(VERSION).array());
stream.write(ByteBuffer.allocate(4).putInt(headersOffset).array());
stream.write(ByteBuffer.allocate(4).putInt(poolOffset).array());
buf.flip();

0 comments on commit b81d689

Please sign in to comment.