# HG changeset patch # User Bernhard Urban # Date 1371045883 -7200 # Node ID 16dfdc920e7751c1702a3f1f7dec19e25f61a212 # Parent 767ef799b32375e0ce96f6c3a5ce42d409d7e72e unittest/aot: add testcase for string objects diff -r 767ef799b323 -r 16dfdc920e77 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java Wed Jun 12 16:04:43 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java Wed Jun 12 16:04:43 2013 +0200 @@ -54,6 +54,7 @@ public class AheadOfTimeCompilationTest extends GraalCompilerTest { public static final Object STATICFINALOBJECT = new Object(); + public static final String STATICFINALSTRING = "test string"; public static Object getStaticFinalObject() { return AheadOfTimeCompilationTest.STATICFINALOBJECT; @@ -136,6 +137,34 @@ assertEquals(0, result.getNodes(ReadNode.class).count()); } + public static String getStringObject() { + return AheadOfTimeCompilationTest.STATICFINALSTRING; + } + + @Test + public void testStringObjectAOT() { + // embedded strings are fine + testStringObjectCommon(true); + } + + @Test + public void testStringObject() { + testStringObjectCommon(false); + } + + private void testStringObjectCommon(boolean compileAOT) { + StructuredGraph result = compile("getStringObject", compileAOT); + + NodeIterable filter = result.getNodes().filter(ConstantNode.class); + assertEquals(1, filter.count()); + Object mirror = filter.first().asConstant().asObject(); + assertEquals(String.class, mirror.getClass()); + assertEquals("test string", mirror); + + assertEquals(0, result.getNodes(FloatingReadNode.class).count()); + assertEquals(0, result.getNodes(ReadNode.class).count()); + } + private StructuredGraph compile(String test, boolean compileAOT) { StructuredGraph graph = parse(test); ResolvedJavaMethod method = graph.method();