diff options
author | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
commit | b6778be91900b8161e705dc2598ef7af86842b0b (patch) | |
tree | d15e8ec18a37eec212f50f1ace27714d7e7d4d34 /test/instrumented/library | |
parent | ac6c76f26d884a94d0c9ff54f055d3f9ab750bac (diff) | |
download | scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.gz scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.bz2 scala-b6778be91900b8161e705dc2598ef7af86842b0b.zip |
Begone t1737...
Diffstat (limited to 'test/instrumented/library')
-rw-r--r-- | test/instrumented/library/scala/runtime/BoxesRunTime.java | 100 | ||||
-rw-r--r-- | test/instrumented/library/scala/runtime/ScalaRunTime.scala | 54 |
2 files changed, 77 insertions, 77 deletions
diff --git a/test/instrumented/library/scala/runtime/BoxesRunTime.java b/test/instrumented/library/scala/runtime/BoxesRunTime.java index 9df2f81bc9..797e9f89dd 100644 --- a/test/instrumented/library/scala/runtime/BoxesRunTime.java +++ b/test/instrumented/library/scala/runtime/BoxesRunTime.java @@ -30,9 +30,9 @@ import scala.math.ScalaNumber; * @contributor Stepan Koltsov * @version 2.0 */ public final class BoxesRunTime -{ +{ private static final int CHAR = 0, BYTE = 1, SHORT = 2, INT = 3, LONG = 4, FLOAT = 5, DOUBLE = 6, OTHER = 7; - + private static int typeCode(Object a) { if (a instanceof java.lang.Integer) return INT; if (a instanceof java.lang.Byte) return BYTE; @@ -43,13 +43,13 @@ public final class BoxesRunTime if (a instanceof java.lang.Float) return FLOAT; return OTHER; } - + private static String boxDescription(Object a) { return "" + a.getClass().getSimpleName() + "(" + a + ")"; } - + /* BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING */ - + public static int booleanBoxCount = 0; public static int characterBoxCount = 0; public static int byteBoxCount = 0; @@ -58,63 +58,63 @@ public final class BoxesRunTime public static int longBoxCount = 0; public static int floatBoxCount = 0; public static int doubleBoxCount = 0; - + public static java.lang.Boolean boxToBoolean(boolean b) { booleanBoxCount++; return java.lang.Boolean.valueOf(b); } - + public static java.lang.Character boxToCharacter(char c) { characterBoxCount++; return java.lang.Character.valueOf(c); } - + public static java.lang.Byte boxToByte(byte b) { byteBoxCount++; return java.lang.Byte.valueOf(b); } - + public static java.lang.Short boxToShort(short s) { shortBoxCount++; return java.lang.Short.valueOf(s); } - + public static java.lang.Integer boxToInteger(int i) { integerBoxCount++; return java.lang.Integer.valueOf(i); } - + public static java.lang.Long boxToLong(long l) { longBoxCount++; return java.lang.Long.valueOf(l); } - + public static java.lang.Float boxToFloat(float f) { floatBoxCount++; return java.lang.Float.valueOf(f); } - + public static java.lang.Double boxToDouble(double d) { doubleBoxCount++; // System.out.println("box " + d); // (new Throwable()).printStackTrace(); return java.lang.Double.valueOf(d); } - + /* UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING */ - + public static boolean unboxToBoolean(Object b) { return b == null ? false : ((java.lang.Boolean)b).booleanValue(); } - + public static char unboxToChar(Object c) { return c == null ? 0 : ((java.lang.Character)c).charValue(); } - + public static byte unboxToByte(Object b) { return b == null ? 0 : ((java.lang.Byte)b).byteValue(); } - + public static short unboxToShort(Object s) { return s == null ? 0 : ((java.lang.Short)s).shortValue(); } @@ -122,22 +122,22 @@ public final class BoxesRunTime public static int unboxToInt(Object i) { return i == null ? 0 : ((java.lang.Integer)i).intValue(); } - + public static long unboxToLong(Object l) { return l == null ? 0 : ((java.lang.Long)l).longValue(); } - + public static float unboxToFloat(Object f) { return f == null ? 0.0f : ((java.lang.Float)f).floatValue(); } - + public static double unboxToDouble(Object d) { // System.out.println("unbox " + d); return d == null ? 0.0d : ((java.lang.Double)d).doubleValue(); } /* COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON */ - + private static int eqTypeCode(Number a) { if ((a instanceof java.lang.Integer) || (a instanceof java.lang.Byte)) return INT; if (a instanceof java.lang.Long) return LONG; @@ -146,8 +146,8 @@ public final class BoxesRunTime if (a instanceof java.lang.Float) return FLOAT; return OTHER; } - - public static boolean equals(Object x, Object y) { + + public static boolean equals(Object x, Object y) { if (x == y) return true; return equals2(x, y); } @@ -162,10 +162,10 @@ public final class BoxesRunTime return equalsCharObject((java.lang.Character)x, y); if (x == null) return y == null; - + return x.equals(y); } - + public static boolean equalsNumObject(java.lang.Number xn, Object y) { if (y instanceof java.lang.Number) return equalsNumNum(xn, (java.lang.Number)y); @@ -173,10 +173,10 @@ public final class BoxesRunTime return equalsNumChar(xn, (java.lang.Character)y); if (xn == null) return y == null; - + return xn.equals(y); } - + public static boolean equalsNumNum(java.lang.Number xn, java.lang.Number yn) { int xcode = eqTypeCode(xn); int ycode = eqTypeCode(yn); @@ -195,10 +195,10 @@ public final class BoxesRunTime } if (xn == null) return yn == null; - + return xn.equals(yn); } - + public static boolean equalsCharObject(java.lang.Character xc, Object y) { if (y instanceof java.lang.Character) return xc.charValue() == ((java.lang.Character)y).charValue(); @@ -206,7 +206,7 @@ public final class BoxesRunTime return equalsNumChar((java.lang.Number)y, xc); if (xc == null) return y == null; - + return xc.equals(y); } @@ -224,11 +224,11 @@ public final class BoxesRunTime default: if (xn == null) return yc == null; - + return xn.equals(yc); } } - + /** Hashcode algorithm is driven by the requirements imposed * by primitive equality semantics, namely that equal objects * have equal hashCodes. The first priority are the integral/char @@ -262,16 +262,16 @@ public final class BoxesRunTime else return n.hashCode(); } public static int hashFromDouble(java.lang.Double n) { - int iv = n.intValue(); + int iv = n.intValue(); double dv = n.doubleValue(); if (iv == dv) return iv; - + long lv = n.longValue(); if (lv == dv) return java.lang.Long.valueOf(lv).hashCode(); else return n.hashCode(); } public static int hashFromFloat(java.lang.Float n) { - int iv = n.intValue(); + int iv = n.intValue(); float fv = n.floatValue(); if (iv == fv) return iv; @@ -289,9 +289,9 @@ public final class BoxesRunTime if (a instanceof Number) return hashFromNumber((Number)a); else return a.hashCode(); } - + /* OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS */ - + /** arg1 + arg2 */ public static Object add(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); @@ -518,7 +518,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + /** -arg */ public static Object negate(Object arg) throws NoSuchMethodException { int code = typeCode(arg); @@ -540,7 +540,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + /** +arg */ public static Object positive(Object arg) throws NoSuchMethodException { int code = typeCode(arg); @@ -650,7 +650,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + /** ~arg */ public static Object complement(Object arg) throws NoSuchMethodException { int code = typeCode(arg); @@ -664,7 +664,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + /** !arg */ public static Object takeNot(Object arg) throws NoSuchMethodException { if (arg instanceof Boolean) { @@ -672,15 +672,15 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + public static Object testEqual(Object arg1, Object arg2) throws NoSuchMethodException { return boxToBoolean(arg1 == arg2); } - + public static Object testNotEqual(Object arg1, Object arg2) throws NoSuchMethodException { return boxToBoolean(arg1 != arg2); } - + public static Object testLessThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); @@ -707,7 +707,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + public static Object testLessOrEqualThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); @@ -734,7 +734,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + public static Object testGreaterOrEqualThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); @@ -761,7 +761,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + public static Object testGreaterThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); @@ -788,7 +788,7 @@ public final class BoxesRunTime } throw new NoSuchMethodException(); } - + /** arg.toChar */ public static java.lang.Character toCharacter(Object arg) throws NoSuchMethodException { if (arg instanceof java.lang.Integer) return boxToCharacter((char)unboxToInt(arg)); @@ -872,5 +872,5 @@ public final class BoxesRunTime if (arg instanceof java.lang.Short) return boxToDouble((double)unboxToShort(arg)); throw new NoSuchMethodException(); } - + } diff --git a/test/instrumented/library/scala/runtime/ScalaRunTime.scala b/test/instrumented/library/scala/runtime/ScalaRunTime.scala index 7c89beca61..a8a74dd8ab 100644 --- a/test/instrumented/library/scala/runtime/ScalaRunTime.scala +++ b/test/instrumented/library/scala/runtime/ScalaRunTime.scala @@ -25,17 +25,17 @@ import java.lang.reflect.{ Modifier, Method => JMethod } */ object ScalaRunTime { def isArray(x: AnyRef): Boolean = isArray(x, 1) - def isArray(x: Any, atLevel: Int): Boolean = + def isArray(x: Any, atLevel: Int): Boolean = x != null && isArrayClass(x.asInstanceOf[AnyRef].getClass, atLevel) private def isArrayClass(clazz: Class[_], atLevel: Int): Boolean = clazz.isArray && (atLevel == 1 || isArrayClass(clazz.getComponentType, atLevel - 1)) - def isValueClass(clazz: Class[_]) = clazz.isPrimitive() - + def isValueClass(clazz: Class[_]) = clazz.isPrimitive() + var arrayApplyCount = 0 var arrayUpdateCount = 0 - + /** Retrieve generic array element */ def array_apply(xs: AnyRef, idx: Int): Any = { arrayApplyCount += 1 @@ -85,7 +85,7 @@ object ScalaRunTime { case x: Array[Boolean] => x.length case x: Array[Unit] => x.length case null => throw new NullPointerException - } + } def array_clone(xs: AnyRef): AnyRef = xs match { case x: Array[AnyRef] => ArrayRuntime.cloneArray(x) @@ -122,7 +122,7 @@ object ScalaRunTime { } arr } - + // Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957 // More background at ticket #2318. def ensureAccessible(m: JMethod): JMethod = { @@ -130,10 +130,10 @@ object ScalaRunTime { try m setAccessible true catch { case _: SecurityException => () } } - m + m } - def checkInitialized[T <: AnyRef](x: T): T = + def checkInitialized[T <: AnyRef](x: T): T = if (x == null) throw new UninitializedError else x abstract class Try[+A] { @@ -143,9 +143,9 @@ object ScalaRunTime { def Try[A](block: => A): Try[A] = new Try[A] with Runnable { private var result: A = _ - private var exception: Throwable = + private var exception: Throwable = try { run() ; null } - catch { + catch { case e: ControlThrowable => throw e // don't catch non-local returns etc case e: Throwable => e } @@ -167,7 +167,7 @@ object ScalaRunTime { def _toString(x: Product): String = x.productIterator.mkString(x.productPrefix + "(", ",", ")") - + def _hashCode(x: Product): Int = { import scala.util.MurmurHash._ val arr = x.productArity @@ -187,7 +187,7 @@ object ScalaRunTime { /** Fast path equality method for inlining; used when -optimise is set. */ - @inline def inlinedEquals(x: Object, y: Object): Boolean = + @inline def inlinedEquals(x: Object, y: Object): Boolean = if (x eq y) true else if (x eq null) false else if (x.isInstanceOf[java.lang.Number]) BoxesRunTime.equalsNumObject(x.asInstanceOf[java.lang.Number], y) @@ -198,20 +198,20 @@ object ScalaRunTime { case y: Product if x.productArity == y.productArity => x.productIterator sameElements y.productIterator case _ => false } - + // hashcode ----------------------------------------------------------- // // Note that these are the implementations called by ##, so they // must not call ## themselves. - + @inline def hash(x: Any): Int = if (x.isInstanceOf[java.lang.Number]) BoxesRunTime.hashFromNumber(x.asInstanceOf[java.lang.Number]) else x.hashCode - + @inline def hash(dv: Double): Int = { val iv = dv.toInt if (iv == dv) return iv - + val lv = dv.toLong if (lv == dv) return lv.hashCode @@ -221,7 +221,7 @@ object ScalaRunTime { @inline def hash(fv: Float): Int = { val iv = fv.toInt if (iv == fv) return iv - + val lv = fv.toLong if (lv == fv) return lv.hashCode else fv.hashCode @@ -236,9 +236,9 @@ object ScalaRunTime { @inline def hash(x: Char): Int = x.toInt @inline def hash(x: Boolean): Int = x.hashCode @inline def hash(x: Unit): Int = 0 - + @inline def hash(x: Number): Int = runtime.BoxesRunTime.hashFromNumber(x) - + /** XXX Why is there one boxed implementation in here? It would seem * we should have all the numbers or none of them. */ @@ -263,15 +263,15 @@ object ScalaRunTime { * called on null and (b) depending on the apparent type of an * array, toString may or may not print it in a human-readable form. * - * @param arg the value to stringify + * @param arg the value to stringify * @return a string representation of <code>arg</code> * - */ + */ def stringOf(arg: Any): String = stringOf(arg, scala.Int.MaxValue) - def stringOf(arg: Any, maxElements: Int): String = { + def stringOf(arg: Any, maxElements: Int): String = { def isScalaClass(x: AnyRef) = Option(x.getClass.getPackage) exists (_.getName startsWith "scala.") - + def isTuple(x: AnyRef) = x.getClass.getName matches """^scala\.Tuple(\d+).*""" @@ -315,13 +315,13 @@ object ScalaRunTime { // The try/catch is defense against iterables which aren't actually designed // to be iterated, such as some scala.tools.nsc.io.AbstractFile derived classes. - val s = + val s = try inner(arg) - catch { + catch { case _: StackOverflowError | _: UnsupportedOperationException => arg.toString } - + val nl = if (s contains "\n") "\n" else "" - nl + s + "\n" + nl + s + "\n" } } |