AdoptOpenJDK/jitwatch

Any plans to support the Vector API?

Ledmington opened this issue · 4 comments

Right now, if you write a simple loop using the Vector API like this:

import jdk.incubator.vector.DoubleVector;
import jdk.incubator.vector.VectorSpecies;
import jdk.incubator.vector.VectorOperators;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;

final class Main {

    private static final RandomGenerator rng = RandomGeneratorFactory.getDefault().create(System.nanoTime());
    private static final VectorSpecies<Double> species = DoubleVector.SPECIES_PREFERRED;

    public static void main(final String[] args){
        final int length = 100_000;
        final double[] v = new double[length];
        for(int i=0; i<length; i++) {
            v[i] = rng.nextDouble(-1.0, 1.0);
        }

        DoubleVector s = DoubleVector.broadcast(species, 0.0);
        for(int i=0; i<species.loopBound(length); i += species.length()) {
            final DoubleVector vi = DoubleVector.fromArray(species, v, i);
            s = s.add(vi);
        }
        System.out.println(s.reduceLanes(VectorOperators.ADD));
    }
}

JitWatch will show you nothing: not even the source code or the bytecode.

Do you have any plans to support it?

Hi @Ledmington if you look in jitwatch.out log file you will see that the current version of JITWatch is unable to parse classes it cannot find. This is the cause of several reported issues and goes back to a poor design decision made long ago when I used classloading as a way of building the class and method model.

I have a new open source project https://github.com/chriswhocodes/ClassAct which is a basic binary classfile parser that does not use the classloader.

Once I replace the existing JITWatch classfile parser with ClassAct then it will be able to support code like this example that uses internal APIs.

I'm hoping I will find time to do this work soon.

Kind regards,

Chris

2023-10-29T12:08:24.285702540Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.AbstractSpecies'
2023-10-29T12:08:24.285995364Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.Double256Vector'
2023-10-29T12:08:24.286637266Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.DoubleVector$DoubleSpecies'
2023-10-29T12:08:24.287094624Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.Double256Vector'
2023-10-29T12:08:24.287852532Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.AbstractSpecies'
2023-10-29T12:08:24.292710923Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.VectorOperators$OperatorImpl'
2023-10-29T12:08:24.292989394Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.DoubleVector$DoubleSpecies'
2023-10-29T12:08:24.293219950Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.AbstractSpecies'
2023-10-29T12:08:24.293438684Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.VectorIntrinsics'
2023-10-29T12:08:24.300703095Z ERR org.adoptopenjdk.jitwatch.util.ParseUtil ClassNotFoundException: 'jdk.incubator.vector.Double256Vector'
2023-10-29T12:08:24.836115912Z ERR org.adoptopenjdk.jitwatch.model.assembly.AssemblyProcessor Could not parse MSP from line: # {method} {0x00007f66130ddf20} 'dummyVector' '()Ljdk/incubator/vector/DoubleVector;' in 'jdk/incubator/vector/DoubleVector$DoubleSpecies'
org.adoptopenjdk.jitwatch.model.LogParseException: Could not parse types: Ljdk/incubator/vector/DoubleVector;
	at org.adoptopenjdk.jitwatch.util.ParseUtil.getClassTypes(ParseUtil.java:373)
	at org.adoptopenjdk.jitwatch.model.MemberSignatureParts.setParamsAndReturn(MemberSignatureParts.java:389)
	at org.adoptopenjdk.jitwatch.model.MemberSignatureParts.fromAssembly(MemberSignatureParts.java:377)
	at org.adoptopenjdk.jitwatch.model.assembly.AssemblyProcessor.attachAssemblyToMembers(AssemblyProcessor.java:277)
	at org.adoptopenjdk.jitwatch.parser.hotspot.HotSpotLogParser.parseAssemblyLines(HotSpotLogParser.java:178)
	at org.adoptopenjdk.jitwatch.parser.hotspot.HotSpotLogParser.parseLogFile(HotSpotLogParser.java:132)
	at org.adoptopenjdk.jitwatch.parser.AbstractLogParser.processLogFile(AbstractLogParser.java:366)
	at org.adoptopenjdk.jitwatch.parser.ILogParser.processLogFile(ILogParser.java:23)
	at org.adoptopenjdk.jitwatch.sandbox.Sandbox.runJITWatch(Sandbox.java:400)
	at org.adoptopenjdk.jitwatch.sandbox.Sandbox.runSandbox(Sandbox.java:199)
	at org.adoptopenjdk.jitwatch.ui.sandbox.SandboxStage.runSandbox(SandboxStage.java:620)
	at org.adoptopenjdk.jitwatch.ui.sandbox.SandboxStage.access$1000(SandboxStage.java:78)
	at org.adoptopenjdk.jitwatch.ui.sandbox.SandboxStage$11.run(SandboxStage.java:395)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: jdk.incubator.vector.DoubleVector
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:534)
	at java.base/java.lang.Class.forName(Class.java:513)
	at org.adoptopenjdk.jitwatch.util.ClassUtil.loadClassWithoutInitialising(ClassUtil.java:55)
	at org.adoptopenjdk.jitwatch.util.ParseUtil.findClassesForTypeString(ParseUtil.java:821)
	at org.adoptopenjdk.jitwatch.util.ParseUtil.getClassTypes(ParseUtil.java:369)
	... 13 more
Thihup commented

Wouldn't it be better to use the new ClassFile API instead?
This way you would not have to update your library every new JDK release.
However this library is internal in JDK 21 and it will probably be in preview in JDK 22

Hi @Thihup

Exactly, I have no control over when ClassFile API becomes available and it won't work with older Java versions. Mine is compatible with JDK8+ and I can tailor the API to its consumers (JITWatch and https://byte-me.dev).

I think those are worth the effort of keeping up with the fairly minor changes in new Java versions :)

... the current version of JITWatch is unable to parse classes it cannot find.

I'm sorry but I don't understand. If the current version of JITWatch uses the class loader to parse classes, shouldn't it be able to parse the jdk.incubator.vector.* classes, since they exist and the JVM can use them? Or maybe is it because JITWatch is built with java 8 support and so, a JVM executing it does not take classes available in new releases into account? Lastly, should the jdk.incubator.vector.jmod file help in this kind of situation or I am missing something?

Anyway, I'm willing to help with your ClassAct project, if needed.