Skip to content

Commit

Permalink
fixed jdk.jfr
Browse files Browse the repository at this point in the history
  • Loading branch information
asotona committed Oct 25, 2023
1 parent 694db07 commit 0587f20
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
jdk.incubator.vector, // participates in preview features
jdk.jartool, // participates in preview features
jdk.jdeps, // participates in preview features
jdk.jfr, // participates in preview features
jdk.jlink, // participates in preview features
jdk.jshell; // participates in preview features
exports jdk.internal.access to
Expand Down
26 changes: 13 additions & 13 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/EventClassBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import jdk.internal.classfile.AnnotationValue;
import jdk.internal.classfile.ClassBuilder;
import jdk.internal.classfile.Classfile;
import jdk.internal.classfile.Label;
import jdk.internal.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import java.lang.classfile.AnnotationValue;
import java.lang.classfile.ClassBuilder;
import java.lang.classfile.ClassFile;
import java.lang.classfile.Label;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import jdk.jfr.AnnotationElement;
import jdk.jfr.Event;
import jdk.jfr.ValueDescriptor;
Expand Down Expand Up @@ -66,7 +66,7 @@ public EventClassBuilder(List<AnnotationElement> annotationElements, List<ValueD
}

public Class<? extends Event> build() {
byte[] bytes = Classfile.of().build(ClassDesc.of(fullClassName), cb -> build(cb));
byte[] bytes = ClassFile.of().build(ClassDesc.of(fullClassName), cb -> build(cb));
Bytecode.log(fullClassName, bytes);
return SecuritySupport.defineClass(Event.class, bytes).asSubclass(Event.class);
}
Expand All @@ -80,7 +80,7 @@ void build(ClassBuilder builder) {

private void buildSetMethod(ClassBuilder builder) {
// void Event::set(int index, Object value);
builder.withMethod(SET_METHOD.name(), SET_METHOD.descriptor(), Classfile.ACC_PUBLIC, methodBuilder -> methodBuilder.withCode(codeBuilder -> {
builder.withMethod(SET_METHOD.name(), SET_METHOD.descriptor(), ClassFile.ACC_PUBLIC, methodBuilder -> methodBuilder.withCode(codeBuilder -> {
int index = 0;
for (ValueDescriptor v : fields) {
codeBuilder.iload(1);
Expand All @@ -101,7 +101,7 @@ private void buildSetMethod(ClassBuilder builder) {
}

private void buildConstructor(ClassBuilder builder) {
builder.withMethod(ConstantDescs.INIT_NAME, ConstantDescs.MTD_void, Classfile.ACC_PUBLIC, methodBuilder -> methodBuilder.withCode(codeBuilder -> {
builder.withMethod(ConstantDescs.INIT_NAME, ConstantDescs.MTD_void, ClassFile.ACC_PUBLIC, methodBuilder -> methodBuilder.withCode(codeBuilder -> {
codeBuilder.aload(0);
invokespecial(codeBuilder, TYPE_EVENT, DEFAULT_CONSTRUCTOR);
codeBuilder.return_();
Expand All @@ -111,26 +111,26 @@ private void buildConstructor(ClassBuilder builder) {
private void buildClassInfo(ClassBuilder builder) {
builder.withSuperclass(Bytecode.classDesc(Event.class));
builder.withFlags(AccessFlag.FINAL, AccessFlag.PUBLIC, AccessFlag.SUPER);
List<jdk.internal.classfile.Annotation> annotations = new ArrayList<>();
List<java.lang.classfile.Annotation> annotations = new ArrayList<>();
for (jdk.jfr.AnnotationElement a : annotationElements) {
List<jdk.internal.classfile.AnnotationElement> list = new ArrayList<>();
List<java.lang.classfile.AnnotationElement> list = new ArrayList<>();
for (ValueDescriptor v : a.getValueDescriptors()) {
// ValueDescriptor can only hold primitive
// No need to care about classes/enums
var value = a.getValue(v.getName());
var av = AnnotationValue.of(value);
var ae = jdk.internal.classfile.AnnotationElement.of(v.getName(), av);
var ae = java.lang.classfile.AnnotationElement.of(v.getName(), av);
list.add(ae);
}
ClassDesc cd = ClassDesc.of(a.getTypeName());
annotations.add(jdk.internal.classfile.Annotation.of(cd, list));
annotations.add(java.lang.classfile.Annotation.of(cd, list));
}
builder.with(RuntimeVisibleAnnotationsAttribute.of(annotations));
}

private void buildFields(ClassBuilder builder) {
for (ValueDescriptor v : fields) {
builder.withField(v.getName(), Bytecode.classDesc(v), Classfile.ACC_PRIVATE);
builder.withField(v.getName(), Bytecode.classDesc(v), ClassFile.ACC_PRIVATE);
// No need to store annotations on field since they will be replaced anyway.
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
import java.util.Set;
import java.util.function.Consumer;

import jdk.internal.classfile.Annotation;
import jdk.internal.classfile.AnnotationElement;
import jdk.internal.classfile.AnnotationValue;
import jdk.internal.classfile.ClassElement;
import jdk.internal.classfile.ClassModel;
import jdk.internal.classfile.Classfile;
import jdk.internal.classfile.CodeBuilder;
import jdk.internal.classfile.CodeBuilder.BlockCodeBuilder;
import jdk.internal.classfile.FieldModel;
import jdk.internal.classfile.Label;
import jdk.internal.classfile.MethodModel;
import jdk.internal.classfile.Opcode;
import jdk.internal.classfile.TypeKind;
import jdk.internal.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import java.lang.classfile.Annotation;
import java.lang.classfile.AnnotationElement;
import java.lang.classfile.AnnotationValue;
import java.lang.classfile.ClassElement;
import java.lang.classfile.ClassModel;
import java.lang.classfile.ClassFile;
import java.lang.classfile.CodeBuilder;
import java.lang.classfile.CodeBuilder.BlockCodeBuilder;
import java.lang.classfile.FieldModel;
import java.lang.classfile.Label;
import java.lang.classfile.MethodModel;
import java.lang.classfile.Opcode;
import java.lang.classfile.TypeKind;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import jdk.jfr.internal.event.EventConfiguration;
import jdk.jfr.internal.event.EventWriter;
import jdk.jfr.Enabled;
Expand Down Expand Up @@ -164,7 +164,7 @@ public String getClassName() {
}

private ClassModel createClassModel(byte[] bytes) {
return Classfile.of().parse(bytes);
return ClassFile.of().parse(bytes);
}

boolean isRegistered() {
Expand Down Expand Up @@ -344,7 +344,7 @@ public byte[] buildInstrumented() {
}

byte[] toByteArray() {
return Classfile.of().build(classModel.thisClass().asSymbol(), classBuilder -> {
return ClassFile.of().build(classModel.thisClass().asSymbol(), classBuilder -> {
for (ClassElement ce : classModel) {
boolean updated = false;
if (ce instanceof MethodModel method) {
Expand Down
10 changes: 5 additions & 5 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/util/Bytecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.internal.classfile.CodeBuilder;
import jdk.internal.classfile.ClassModel;
import jdk.internal.classfile.Classfile;
import jdk.internal.classfile.components.ClassPrinter;
import java.lang.classfile.CodeBuilder;
import java.lang.classfile.ClassModel;
import java.lang.classfile.ClassFile;
import java.lang.classfile.components.ClassPrinter;

/**
* Helper class when working with bytecode.
Expand Down Expand Up @@ -158,7 +158,7 @@ public static void log(String className, byte[] bytes) {
StringBuilder out = new StringBuilder();
out.append("Bytecode:");
out.append(System.lineSeparator());
ClassModel classModel = Classfile.of().parse(bytes);
ClassModel classModel = ClassFile.of().parse(bytes);
ClassPrinter.toYaml(classModel, ClassPrinter.Verbosity.TRACE_ALL, out::append);
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.TRACE, out.toString());
}
Expand Down
3 changes: 3 additions & 0 deletions src/jdk.jfr/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
* questions.
*/

import jdk.internal.javac.ParticipatesInPreview;

/**
* Defines the API for JDK Flight Recorder.
*
* @moduleGraph
* @since 9
*/
@ParticipatesInPreview
module jdk.jfr {
exports jdk.jfr;
exports jdk.jfr.consumer;
Expand Down

0 comments on commit 0587f20

Please sign in to comment.