Permalink
Browse files

Merge branch 'master' into fast

  • Loading branch information...
2 parents ad3d2f0 + 852a031 commit 3e92a39a8e5ee3b2e3580075c993a5341cfe1a90 @headius headius committed Aug 21, 2010
View
@@ -29,7 +29,7 @@
<classpathentry kind="lib" path="build_lib/asm-commons-3.2.jar"/>
<classpathentry kind="lib" path="build_lib/asm-util-3.2.jar"/>
<classpathentry kind="lib" path="build_lib/jnr-posix.jar"/>
- <classpathentry kind="lib" path="build_lib/joda-time-1.6.jar"/>
+ <classpathentry kind="lib" path="build_lib/joda-time-1.6.1.jar"/>
<classpathentry kind="lib" path="build_lib/jgrapht-jdk1.5.jar"/>
<classpathentry kind="lib" path="build_lib/livetribe-jsr223-2.0.6.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ANT"/>
@@ -107,15 +107,16 @@ def open(ident=nil, opt=nil, fac=nil)
self
end
- alias_method :open!, :open
##
# like open, but closes it first
- def reopen(*args)
+ def reopen(*args, &block)
close
- open(*args)
+ open(*args, &block)
end
+ alias_method :open!, :reopen
+
##
# Is it open?
def opened?
@@ -1 +0,0 @@
-fails:String#sub! with pattern and block raises a RuntimeError when self is frozen
@@ -1 +0,0 @@
-fails(JRUBY-2791,macos):Socket::IPSocket#addr returns an array with the socket's information
@@ -1 +0,0 @@
-fails(JRUBY-2791,macos):Socket::IPSocket#peeraddr returns an array of information on the peer
@@ -1 +0,0 @@
-fails(JRUBY-2791,macos):TCPSocket#gethostbyname returns the canonical name as first value
@@ -1,12 +0,0 @@
-fails:String#% supports binary formats using %b for negative numbers
-fails:String#% supports negative integers using %d, giving priority to `-`
-fails:String#% supports negative integers using %i, giving priority to `-`
-fails:String#% supports octal formats using %o for negative numbers
-fails:String#% supports negative bignums with %u or %d
-fails:String#% supports hex formats using %x for negative numbers
-fails:String#% supports hex formats using %X for negative numbers
-fails:String#% behaves as if calling Kernel#Float for %e arguments, when the passed argument is hexadecimal string
-fails:String#% behaves as if calling Kernel#Float for %E arguments, when the passed argument is hexadecimal string
-fails:String#% behaves as if calling Kernel#Float for %f arguments, when the passed argument is hexadecimal string
-fails:String#% behaves as if calling Kernel#Float for %g arguments, when the passed argument is hexadecimal string
-fails:String#% behaves as if calling Kernel#Float for %G arguments, when the passed argument is hexadecimal string
@@ -3208,7 +3208,9 @@ public RaiseException newIllegalSequence(String message) {
}
public RaiseException newNoMethodError(String message, String name, IRubyObject args) {
- return new RaiseException(new RubyNoMethodError(this, getNoMethodError(), message, name, args), true);
+ RaiseException exception = new RaiseException(new RubyNoMethodError(this, getNoMethodError(), message, name, args), true);
+ exception.preRaise(getCurrentContext());
+ return exception;
}
public RaiseException newNameError(String message, String name) {
@@ -3223,29 +3225,39 @@ public RaiseException newNameError(String message, String name, Throwable origEx
if (printWhenVerbose && origException != null && this.isVerbose()) {
origException.printStackTrace(getErrorStream());
}
- return new RaiseException(new RubyNameError(
+
+ RaiseException exception = new RaiseException(new RubyNameError(
this, getNameError(), message, name), false);
+ exception.preRaise(getCurrentContext());
+
+ return exception;
}
public RaiseException newLocalJumpError(RubyLocalJumpError.Reason reason, IRubyObject exitValue, String message) {
- return new RaiseException(new RubyLocalJumpError(this, getLocalJumpError(), message, reason, exitValue), true);
+ RaiseException exception = new RaiseException(new RubyLocalJumpError(this, getLocalJumpError(), message, reason, exitValue), true);
+ exception.preRaise(getCurrentContext());
+ return exception;
}
public RaiseException newLocalJumpErrorNoBlock() {
return newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, getNil(), "no block given");
}
public RaiseException newRedoLocalJumpError() {
- return new RaiseException(new RubyLocalJumpError(this, getLocalJumpError(), "unexpected redo", RubyLocalJumpError.Reason.REDO, getNil()), true);
+ return newLocalJumpError(RubyLocalJumpError.Reason.REDO, getNil(), "unexpected redo");
}
public RaiseException newLoadError(String message) {
return newRaiseException(getLoadError(), message);
}
public RaiseException newFrozenError(String objectType) {
+ return newFrozenError(objectType, false);
+ }
+
+ public RaiseException newFrozenError(String objectType, boolean runtimeError) {
// TODO: Should frozen error have its own distinct class? If not should more share?
- return newRaiseException(is1_9() ? getRuntimeError() : getTypeError(), "can't modify frozen " + objectType);
+ return newRaiseException(is1_9() || runtimeError ? getRuntimeError() : getTypeError(), "can't modify frozen " + objectType);
}
public RaiseException newSystemStackError(String message) {
@@ -3260,7 +3272,9 @@ public RaiseException newSystemStackError(String message, StackOverflowError soe
}
public RaiseException newSystemExit(int status) {
- return new RaiseException(RubySystemExit.newInstance(this, status));
+ RaiseException exception = new RaiseException(RubySystemExit.newInstance(this, status));
+ exception.preRaise(getCurrentContext());
+ return exception;
}
public RaiseException newIOError(String message) {
@@ -71,6 +71,7 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.IAutoloadMethod;
import org.jruby.runtime.load.LoadService;
+import org.jruby.util.ConvertBytes;
import org.jruby.util.IdUtil;
import org.jruby.util.ShellLauncher;
import org.jruby.util.TypeConverter;
@@ -267,7 +268,9 @@ private static IRubyObject methodMissing(ThreadContext context, IRubyObject recv
exArgs = new IRubyObject[]{msg, symbol};
}
- throw new RaiseException((RubyException)exc.newInstance(context, exArgs, Block.NULL_BLOCK));
+ RaiseException exception = new RaiseException((RubyException)exc.newInstance(context, exArgs, Block.NULL_BLOCK));
+ exception.preRaise(context);
+ throw exception;
}
@JRubyMethod(name = "open", required = 1, optional = 2, frame = true, module = true, visibility = PRIVATE)
@@ -363,22 +366,26 @@ public static RubyFloat new_float(IRubyObject recv, IRubyObject object) {
@JRubyMethod(name = "Float", module = true, visibility = PRIVATE, compat = CompatVersion.RUBY1_9)
public static RubyFloat new_float19(IRubyObject recv, IRubyObject object) {
+ Ruby runtime = recv.getRuntime();
if(object instanceof RubyFixnum){
- return RubyFloat.newFloat(object.getRuntime(), ((RubyFixnum)object).getDoubleValue());
- }else if(object instanceof RubyFloat){
+ return RubyFloat.newFloat(runtime, ((RubyFixnum)object).getDoubleValue());
+ } else if (object instanceof RubyFloat) {
return (RubyFloat)object;
- }else if(object instanceof RubyBignum){
- return RubyFloat.newFloat(object.getRuntime(), RubyBignum.big2dbl((RubyBignum)object));
- }else if(object instanceof RubyString){
+ } else if(object instanceof RubyBignum){
+ return RubyFloat.newFloat(runtime, RubyBignum.big2dbl((RubyBignum)object));
+ } else if(object instanceof RubyString){
if(((RubyString) object).getByteList().getRealSize() == 0){ // rb_cstr_to_dbl case
- throw recv.getRuntime().newArgumentError("invalid value for Float(): " + object.inspect());
+ throw runtime.newArgumentError("invalid value for Float(): " + object.inspect());
}
- return RubyNumeric.str2fnum(recv.getRuntime(),(RubyString)object,true);
- }else if(object.isNil()){
- throw recv.getRuntime().newTypeError("can't convert nil into Float");
+ RubyString arg = (RubyString)object;
+ if (arg.toString().startsWith("0x")) {
+ return ConvertBytes.byteListToInum19(runtime, arg.getByteList(), 16, true).toFloat();
+ }
+ return RubyNumeric.str2fnum19(runtime, arg,true);
+ } else if(object.isNil()){
+ throw runtime.newTypeError("can't convert nil into Float");
} else {
- RubyFloat rFloat = (RubyFloat)TypeConverter.convertToType19(object, recv.getRuntime().getFloat(), "to_f");
- return rFloat;
+ return (RubyFloat)TypeConverter.convertToType19(object, runtime.getFloat(), "to_f");
}
}
@@ -705,7 +705,11 @@ private final void modifyCheck(byte[] b, int len, Encoding enc) {
}
private void frozenCheck() {
- if (isFrozen()) throw getRuntime().newFrozenError("string");
+ frozenCheck(false);
+ }
+
+ private void frozenCheck(boolean runtimeError) {
+ if (isFrozen()) throw getRuntime().newFrozenError("string", runtimeError);
}
/** rb_str_modify
@@ -2391,14 +2395,14 @@ private IRubyObject subBangIter(ThreadContext context, Regex pattern, Block bloc
DynamicScope scope = context.getCurrentScope();
if (matcher.search(value.getBegin(), range, Option.NONE) >= 0) {
- frozenCheck();
+ frozenCheck(true);
byte[] bytes = value.getUnsafeBytes();
int size = value.getRealSize();
RubyMatchData match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
RubyString repl = objAsString(context, block.yield(context,
makeShared(context.getRuntime(), matcher.getBegin(), matcher.getEnd() - matcher.getBegin())));
modifyCheck(bytes, size);
- frozenCheck();
+ frozenCheck(true);
scope.setBackRef(match);
return subBangCommon(context, pattern, matcher, repl, repl.flags);
} else {
@@ -1719,10 +1719,14 @@ public Operand buildEnsureNode(Node node, IR_Scope m) {
// ensure
// .. something else ..
// end
+ //
if (ebi.noFallThru)
m.addInstr(new LABEL_Instr(ebi.start));
+ // Pop the current ensure block info node *BEFORE* generating the ensure code for this block itself!
+ _ensureBlockStack.pop();
+
// Two cases:
// 1. Ensure block has no explicit return => the result of the entire ensure expression is the result of the protected body.
// 2. Ensure block has an explicit return => the result of the protected body is ignored.
@@ -1736,8 +1740,6 @@ public Operand buildEnsureNode(Node node, IR_Scope m) {
m.addInstr(new LABEL_Instr(ebi.end));
}
- _ensureBlockStack.pop();
-
return rv;
}
@@ -2690,7 +2692,7 @@ public Operand buildRetry(Node node, IR_Scope s) {
public Operand buildReturn(ReturnNode returnNode, IR_Scope m) {
Operand retVal = (returnNode.getValueNode() == null) ? Nil.NIL : build(returnNode.getValueNode(), m);
- // Before we return, have to go execute all the ensure blocks
+ // Before we return, have to go execute all the ensure blocks (except the one we are currently executing!)
if (!_ensureBlockStack.empty())
EnsureBlockInfo.emitJumpChain(m, _ensureBlockStack);
m.addInstr(new RETURN_Instr(retVal));
@@ -223,6 +223,17 @@ void markDeadInstructions()
{
// System.out.println("dead processing for " + _bb.getID());
LiveVariablesProblem lvp = (LiveVariablesProblem)_prob;
+
+ if (_out == null) {
+ // _out cannot be null for reachable bbs!
+ // This bb is unreachable! (or we have a mighty bug!)
+ // Mark everything dead in here!
+ for (IR_Instr i: _bb.getInstrs())
+ i.markDead();
+
+ return;
+ }
+
_tmp = (BitSet)_out.clone();
// Traverse the instructions in this basic block in reverse order!
@@ -156,6 +156,7 @@ private BasicBlock createNewBB(DirectedGraph<BasicBlock, CFG_Edge> g, Map<Label,
private void removeBB(BasicBlock b) {
_cfg.removeVertex(b);
+ _bbMap.remove(b._label);
_bbRescuerMap.remove(b);
// SSS FIXME: Patch up rescued regions as well??
}
@@ -333,11 +334,11 @@ else if (i instanceof BREAK_Instr) {
rr.setFirstRescueBB(firstRescueBB);
// 2. Record a mapping from the region's exclusive basic blocks to the first bb that will start exception handling for all their exceptions.
- for (BasicBlock b: rr._exclusiveBBs)
+ // 3. Add an exception edge from every exclusive bb of the region to firstRescueBB
+ for (BasicBlock b: rr._exclusiveBBs) {
_bbRescuerMap.put(b, firstRescueBB);
-
- // 3. Add an exception edge from the last bb of the region to firstRescueBB
- g.addEdge(rr._endBB, firstRescueBB)._type = CFG_Edge_Type.EXCEPTION_EDGE;
+ g.addEdge(b, firstRescueBB)._type = CFG_Edge_Type.EXCEPTION_EDGE;
+ }
}
// Dummy entry and exit basic blocks and other dummy edges are needed to maintain the CFG
@@ -364,14 +365,17 @@ else if (i instanceof BREAK_Instr) {
g.addEdge(currBB, _exitBB)._type = CFG_Edge_Type.DUMMY_EDGE;
}
+ _cfg = g;
+
+ // Delete orphaned (with no incoming edges) blocks
+ deleteOrphanedBlocks();
+
// Set up the bb array
int n = getMaxNodeID();
_bbArray = new BasicBlock[n];
for (BasicBlock x : _bbMap.values()) {
_bbArray[x.getID() - 1] = x;
}
-
- _cfg = g;
}
private void mergeBBs(BasicBlock a, BasicBlock b) {
@@ -775,6 +779,31 @@ private void pushBBOnStack(Stack<BasicBlock> stack, BitSet bbSet, BasicBlock bb)
}
}
+ public void deleteOrphanedBlocks() {
+ System.out.println("\nGraph:\n" + getGraph().toString());
+ System.out.println("\nInstructions:\n" + toStringInstrs());
+
+ // FIXME: Quick and dirty implementation
+ while (true) {
+ BasicBlock bbToRemove = null;
+ for (BasicBlock b: getNodes()) {
+ // Skip entry bb!
+ if (b == _entryBB)
+ continue;
+
+ // Every other bb should have at least one incoming edge
+ if (incomingEdgesOf(b).size() == 0) {
+ bbToRemove = b;
+ break;
+ }
+ }
+ if (bbToRemove == null)
+ break;
+ else
+ removeBB(bbToRemove);
+ }
+ }
+
public List<BasicBlock> linearize() {
_linearizedBBList = new ArrayList<BasicBlock>();
@@ -102,13 +102,6 @@ public final IRubyObject initialize(ThreadContext context,
public final String toString() {
return String.format("MemoryPointer[address=%#x, size=%d]", getAddress(), size);
}
-
- @Override
- @JRubyMethod(name = { "to_s", "inspect" })
- public final IRubyObject inspect(ThreadContext context) {
- return RubyString.newString(context.getRuntime(),
- String.format("#<MemoryPointer address=%#x size=%d>", getAddress(), size));
- }
@JRubyMethod(name = "free")
public final IRubyObject free(ThreadContext context) {
@@ -111,17 +111,13 @@ public IRubyObject null_p(ThreadContext context) {
@Override
- @JRubyMethod(name = "to_s", optional = 1)
+ @JRubyMethod(name = { "to_s", "inspect" }, optional = 1)
public IRubyObject to_s(ThreadContext context, IRubyObject[] args) {
- return RubyString.newString(context.getRuntime(),
- String.format("Pointer [address=%x]", getAddress()));
- }
+ String s = size != Long.MAX_VALUE
+ ? String.format("#<%s address=0x%x size=%s>", getMetaClass().getName(), getAddress(), size)
+ : String.format("#<%s address=0x%x>", getMetaClass().getName(), getAddress());
- @JRubyMethod(name = "inspect")
- public IRubyObject inspect(ThreadContext context) {
- String hex = Long.toHexString(getAddress());
- return RubyString.newString(context.getRuntime(),
- String.format("#<Pointer address=0x%s>", hex));
+ return RubyString.newString(context.getRuntime(), s);
}
@JRubyMethod(name = { "address", "to_i" })
Oops, something went wrong.

0 comments on commit 3e92a39

Please sign in to comment.