Skip to content

Commit

Permalink
Follow up fix to #2840. TraceInstr was missing decode(). String was e…
Browse files Browse the repository at this point in the history
…ncode/decode needed ability

to deal with null.
  • Loading branch information
enebo committed Apr 17, 2015
1 parent 854b79a commit 1009f65
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/ir/instructions/TraceInstr.java
@@ -1,6 +1,7 @@
package org.jruby.ir.instructions;

import org.jruby.ir.Operation;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
Expand Down Expand Up @@ -58,12 +59,16 @@ public String[] toStringNonOperandArgs() {
@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getEvent().ordinal());
e.encode(getEvent());
e.encode(getName());
e.encode(getFilename());
e.encode(getLinenumber());
}

public static TraceInstr decode(IRReaderDecoder d) {
return new TraceInstr(d.decodeRubyEvent(), d.decodeString(), d.decodeString(), d.decodeInt());
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
if (context.runtime.hasEventHooks()) {
Expand Down
Expand Up @@ -30,4 +30,6 @@ interface IRPersistenceValues {
public final static byte FULL = (byte) 255;

public final static int PROLOGUE_LENGTH = 2 * 4; // 2 ints at front

public final static int NULL_STRING = -1;
}
Expand Up @@ -20,6 +20,7 @@

import java.util.List;
import java.util.Map;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.Signature;
import org.jruby.util.ByteList;

Expand Down Expand Up @@ -50,6 +51,7 @@ public interface IRReaderDecoder {
public double decodeDouble();
public float decodeFloat();
public Label decodeLabel();
public RubyEvent decodeRubyEvent();
public Signature decodeSignature();

public Variable decodeVariable();
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/org/jruby/ir/persistence/IRReaderStream.java
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.Signature;
import org.jruby.util.ByteList;

Expand Down Expand Up @@ -101,9 +102,17 @@ public Label decodeLabel() {
return (Label) decodeOperand();
}

@Override
public RubyEvent decodeRubyEvent() {
return RubyEvent.fromOrdinal(decodeInt());
}

@Override
public String decodeString() {
int strLength = decodeInt();

if (strLength == NULL_STRING) return null;

byte[] bytes = new byte[strLength]; // FIXME: This seems really innefficient
buf.get(bytes);

Expand Down Expand Up @@ -261,7 +270,7 @@ public Instr decodeInstr() {
case RUNTIME_HELPER: return RuntimeHelperCall.decode(this);
case SEARCH_CONST: return SearchConstInstr.decode(this);
case SET_CAPTURED_VAR: return SetCapturedVarInstr.decode(this);
// FIXME: case TRACE: ...
case TRACE: return TraceInstr.decode(this);
case THREAD_POLL: return ThreadPollInstr.decode(this);
case THROW: return ThrowExceptionInstr.decode(this);
case TO_ARY: return ToAryInstr.decode(this);
Expand Down
Expand Up @@ -17,6 +17,7 @@

import java.util.HashMap;
import java.util.Map;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.Signature;
import org.jruby.util.ByteList;

Expand Down Expand Up @@ -120,6 +121,10 @@ public void encode(double value) {
public void encode(Signature value) {
}

@Override
public void encode(RubyEvent event) {
}

@Override
public void startEncodingScopeHeader(IRScope scope) {
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.parser.StaticScope.Type;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.Signature;
import org.jruby.util.ByteList;

Expand All @@ -27,6 +28,7 @@ public interface IRWriterEncoder {
public void encode(IRScope scope);
public void encode(IRScopeType value);
public void encode(Signature signature);
public void encode(RubyEvent event);
public void encode(Type value);
public void encode(Operation value);
public void encode(Operand value);
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/java/org/jruby/ir/persistence/IRWriterStream.java
Expand Up @@ -23,6 +23,7 @@
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.Signature;
import org.jruby.util.ByteList;

Expand Down Expand Up @@ -139,8 +140,12 @@ public void encode(Encoding encoding) {

@Override
public void encode(String value) {
encode(value.length());
buf.put(value.getBytes());
if (value == null) {
encode(NULL_STRING);
} else {
encode(value.length());
buf.put(value.getBytes());
}
}

// This cannot tell difference between null and [] which is ok. Possibly we should even allow
Expand Down Expand Up @@ -194,6 +199,11 @@ public void encode(Signature signature) {
encode(signature.encode());
}

@Override
public void encode(RubyEvent event) {
encode((byte) event.ordinal());
}

@Override
public void encode(StaticScope.Type value) {
encode((byte) value.ordinal());
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/runtime/RubyEvent.java
Expand Up @@ -40,5 +40,9 @@ public int getLineNumberOffset(){
public String getName(){
return event_name;
}

public static RubyEvent fromOrdinal(int value) {
return value < 0 || value >= values().length ? null : values()[value];
}
}

0 comments on commit 1009f65

Please sign in to comment.