org.adoptopenjdk.jitwatch.jarscan.instructioncount.InstructionCountOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jitwatch-jarscan-maven-plugin Show documentation
Show all versions of jitwatch-jarscan-maven-plugin Show documentation
A Maven plugin that scans the project artifact and its dependencies for methods that cannot be inlined by the JIT
compiler. It uses the JarScan utility from the JITWatch project to do that.
See https://github.com/AdoptOpenJDK/jitwatch .
The newest version!
/*
* Copyright (c) 2013-2016 Chris Newland.
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
*/
package org.adoptopenjdk.jitwatch.jarscan.instructioncount;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.S_NEWLINE;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_COMMA;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import org.adoptopenjdk.jitwatch.jarscan.IJarScanOperation;
import org.adoptopenjdk.jitwatch.model.bytecode.BytecodeInstruction;
import org.adoptopenjdk.jitwatch.model.bytecode.MemberBytecode;
import org.adoptopenjdk.jitwatch.model.bytecode.Opcode;
public class InstructionCountOperation implements IJarScanOperation
{
private Map opcodeCountMap;
private int limit;
public InstructionCountOperation(int limit)
{
opcodeCountMap = new EnumMap<>(Opcode.class);
this.limit = limit;
}
@Override
public String getReport()
{
StringBuilder builder = new StringBuilder();
List> sortedList = new ArrayList<>(opcodeCountMap.entrySet());
Collections.sort(sortedList, new Comparator>()
{
@Override
public int compare(Map.Entry o1, Map.Entry o2)
{
return o2.getValue().compareTo(o1.getValue());
}
});
int outputCount = 0;
for (Map.Entry entry : sortedList)
{
Opcode opcode = entry.getKey();
Integer count = entry.getValue();
builder.append(opcode.getMnemonic()).append(C_COMMA);
builder.append(count).append(S_NEWLINE);
outputCount++;;
if (limit != 0 && outputCount == limit)
{
break;
}
}
return builder.toString();
}
private void count(Opcode opcode)
{
Integer count = opcodeCountMap.get(opcode);
if (count == null)
{
count = new Integer(1);
}
else
{
count++;
}
opcodeCountMap.put(opcode, count);
}
@Override
public void processInstructions(String className, MemberBytecode memberBytecode)
{
List instructions = memberBytecode.getInstructions();
for (BytecodeInstruction instruction : instructions)
{
Opcode opcode = instruction.getOpcode();
count(opcode);
}
}
}