Skip to content

Commit

Permalink
Rewrote method overloading bytecode test to rely on local classes not…
Browse files Browse the repository at this point in the history
… core libs
  • Loading branch information
chriswhocodes committed Jan 17, 2017
1 parent 35c4fb4 commit 333de19
Showing 1 changed file with 32 additions and 27 deletions.
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2016 Chris Newland. * Copyright (c) 2013-2017 Chris Newland.
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD * Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki * Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
*/ */
Expand All @@ -9,6 +9,7 @@
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE; import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE;
import static org.junit.Assert.*; import static org.junit.Assert.*;


import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


Expand Down Expand Up @@ -772,17 +773,31 @@ public void testStaticInitialiserRegression()


assertEquals(43, instructions.size()); assertEquals(43, instructions.size());
} }

public int exampleOverloadedMethod(Object object)
{
return object.hashCode();
}

public int exampleOverloadedMethod(String string)
{
return string.hashCode();
}


@Test private void doTestOverloadedMethod(Class<?> paramClass)
public void testRegressionLoadJavaIoPrintStreamString()
{ {
String className = "java.io.PrintStream"; String className = getClass().getName();
String methodName = "print"; String methodName = "exampleOverloadedMethod";


IMetaMember member = UnitTestUtil.createTestMetaMember(className, methodName, new Class<?>[] { java.lang.String.class }, IMetaMember member = UnitTestUtil.createTestMetaMember(className, methodName, new Class<?>[] { paramClass },
void.class); int.class);


ClassBC classBytecode = BytecodeLoader.fetchBytecodeForClass(new ArrayList<String>(), className, false); String thisClassLocation = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();

List<String> classPath = new ArrayList<String>();
classPath.add(thisClassLocation);

ClassBC classBytecode = BytecodeLoader.fetchBytecodeForClass(classPath, className, false);


MemberBytecode memberBytecode = classBytecode.getMemberBytecode(member); MemberBytecode memberBytecode = classBytecode.getMemberBytecode(member);


Expand All @@ -792,29 +807,19 @@ public void testRegressionLoadJavaIoPrintStreamString()


assertNotNull(instructions); assertNotNull(instructions);


assertEquals(8, instructions.size()); assertEquals(3, instructions.size());
} }

@Test @Test
public void testRegressionLoadJavaIoPrintStreamObject() public void testExampleOverloadedMethodString()
{ {
String className = "java.io.PrintStream"; doTestOverloadedMethod(java.lang.String.class);
String methodName = "print"; }

IMetaMember member = UnitTestUtil.createTestMetaMember(className, methodName, new Class<?>[] { java.lang.Object.class },
void.class);

ClassBC classBytecode = BytecodeLoader.fetchBytecodeForClass(new ArrayList<String>(), className, false);

MemberBytecode memberBytecode = classBytecode.getMemberBytecode(member);

assertNotNull(memberBytecode);

List<BytecodeInstruction> instructions = memberBytecode.getInstructions();

assertNotNull(instructions);


assertEquals(5, instructions.size()); @Test
public void testExampleOverloadedMethodObject()
{
doTestOverloadedMethod(java.lang.Object.class);
} }


@Test @Test
Expand Down

0 comments on commit 333de19

Please sign in to comment.