24
25 import java.io.IOException;
26 import java.lang.classfile.Attributes;
27 import java.lang.constant.ClassDesc;
28 import java.net.URI;
29 import java.nio.file.FileSystems;
30 import java.nio.file.Files;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.lang.classfile.ClassFile;
34 import java.lang.classfile.ClassReader;
35 import java.lang.classfile.constantpool.ConstantPoolBuilder;
36 import java.lang.constant.MethodTypeDesc;
37 import jdk.internal.classfile.impl.AbstractPseudoInstruction;
38 import jdk.internal.classfile.impl.LabelContext;
39 import jdk.internal.classfile.impl.ClassFileImpl;
40 import jdk.internal.classfile.impl.RawBytecodeHelper;
41 import jdk.internal.classfile.impl.SplitConstantPool;
42 import jdk.internal.classfile.impl.StackCounter;
43 import jdk.internal.classfile.impl.StackMapGenerator;
44 import org.openjdk.jmh.annotations.Benchmark;
45 import org.openjdk.jmh.annotations.BenchmarkMode;
46 import org.openjdk.jmh.annotations.Fork;
47 import org.openjdk.jmh.annotations.Level;
48 import org.openjdk.jmh.annotations.Measurement;
49 import org.openjdk.jmh.annotations.Mode;
50 import org.openjdk.jmh.annotations.Scope;
51 import org.openjdk.jmh.annotations.Setup;
52 import org.openjdk.jmh.annotations.State;
53 import org.openjdk.jmh.annotations.Warmup;
54 import org.openjdk.jmh.infra.Blackhole;
55
56 @BenchmarkMode(Mode.Throughput)
57 @State(Scope.Benchmark)
58 @Fork(value = 1, jvmArgs = {
59 "--add-exports", "java.base/jdk.internal.classfile.impl=ALL-UNNAMED"})
60 @Warmup(iterations = 2)
61 @Measurement(iterations = 8)
62 public class CodeAttributeTools {
63
93 com.exceptionHandlers().stream().map(eh -> (AbstractPseudoInstruction.ExceptionCatchImpl)eh).toList()));
94 });
95 }
96 } catch (IOException e) {
97 throw new RuntimeException(e);
98 }
99 });
100 }
101
102 @Benchmark
103 public void benchmarkStackMapsGenerator(Blackhole bh) {
104 for (var d : data) bh.consume(new StackMapGenerator(
105 d.labelContext(),
106 d.thisClass(),
107 d.methodName(),
108 d.methodDesc(),
109 d.isStatic(),
110 d.bytecode(),
111 (SplitConstantPool)d.constantPool(),
112 (ClassFileImpl)ClassFile.of(),
113 d.handlers()));
114 }
115
116 @Benchmark
117 public void benchmarkStackCounter(Blackhole bh) {
118 for (var d : data) bh.consume(new StackCounter(
119 d.labelContext(),
120 null,
121 d.thisClass(),
122 d.methodName(),
123 d.methodDesc(),
124 d.isStatic(),
125 d.bytecode(),
126 (SplitConstantPool)d.constantPool(),
127 d.handlers()));
128 }
129 }
|
24
25 import java.io.IOException;
26 import java.lang.classfile.Attributes;
27 import java.lang.constant.ClassDesc;
28 import java.net.URI;
29 import java.nio.file.FileSystems;
30 import java.nio.file.Files;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.lang.classfile.ClassFile;
34 import java.lang.classfile.ClassReader;
35 import java.lang.classfile.constantpool.ConstantPoolBuilder;
36 import java.lang.constant.MethodTypeDesc;
37 import jdk.internal.classfile.impl.AbstractPseudoInstruction;
38 import jdk.internal.classfile.impl.LabelContext;
39 import jdk.internal.classfile.impl.ClassFileImpl;
40 import jdk.internal.classfile.impl.RawBytecodeHelper;
41 import jdk.internal.classfile.impl.SplitConstantPool;
42 import jdk.internal.classfile.impl.StackCounter;
43 import jdk.internal.classfile.impl.StackMapGenerator;
44 import jdk.internal.classfile.impl.WritableField;
45 import org.openjdk.jmh.annotations.Benchmark;
46 import org.openjdk.jmh.annotations.BenchmarkMode;
47 import org.openjdk.jmh.annotations.Fork;
48 import org.openjdk.jmh.annotations.Level;
49 import org.openjdk.jmh.annotations.Measurement;
50 import org.openjdk.jmh.annotations.Mode;
51 import org.openjdk.jmh.annotations.Scope;
52 import org.openjdk.jmh.annotations.Setup;
53 import org.openjdk.jmh.annotations.State;
54 import org.openjdk.jmh.annotations.Warmup;
55 import org.openjdk.jmh.infra.Blackhole;
56
57 @BenchmarkMode(Mode.Throughput)
58 @State(Scope.Benchmark)
59 @Fork(value = 1, jvmArgs = {
60 "--add-exports", "java.base/jdk.internal.classfile.impl=ALL-UNNAMED"})
61 @Warmup(iterations = 2)
62 @Measurement(iterations = 8)
63 public class CodeAttributeTools {
64
94 com.exceptionHandlers().stream().map(eh -> (AbstractPseudoInstruction.ExceptionCatchImpl)eh).toList()));
95 });
96 }
97 } catch (IOException e) {
98 throw new RuntimeException(e);
99 }
100 });
101 }
102
103 @Benchmark
104 public void benchmarkStackMapsGenerator(Blackhole bh) {
105 for (var d : data) bh.consume(new StackMapGenerator(
106 d.labelContext(),
107 d.thisClass(),
108 d.methodName(),
109 d.methodDesc(),
110 d.isStatic(),
111 d.bytecode(),
112 (SplitConstantPool)d.constantPool(),
113 (ClassFileImpl)ClassFile.of(),
114 WritableField.UnsetField.EMPTY_ARRAY,
115 d.handlers()));
116 }
117
118 @Benchmark
119 public void benchmarkStackCounter(Blackhole bh) {
120 for (var d : data) bh.consume(new StackCounter(
121 d.labelContext(),
122 null,
123 d.thisClass(),
124 d.methodName(),
125 d.methodDesc(),
126 d.isStatic(),
127 d.bytecode(),
128 (SplitConstantPool)d.constantPool(),
129 d.handlers()));
130 }
131 }
|