Skip to content

Commit 7dbab81

Browse files
liachJornVernee
authored andcommitted
8304161: Add TypeKind.from to derive from TypeDescriptor.OfField
Reviewed-by: jvernee
1 parent d4eb395 commit 7dbab81

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

src/java.base/share/classes/jdk/internal/classfile/TypeKind.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525

2626
package jdk.internal.classfile;
2727

28+
import java.lang.invoke.TypeDescriptor;
29+
2830
/**
2931
* Describes the types that can be part of a field or method descriptor.
3032
*/
@@ -132,4 +134,12 @@ public static TypeKind fromDescriptor(CharSequence s) {
132134
default -> throw new IllegalArgumentException("Bad type: " + s);
133135
};
134136
}
137+
138+
/**
139+
* {@return the type kind associated with the specified field descriptor}
140+
* @param descriptor the field descriptor
141+
*/
142+
public static TypeKind from(TypeDescriptor.OfField<?> descriptor) {
143+
return fromDescriptor(descriptor.descriptorString());
144+
}
135145
}

src/java.base/share/classes/jdk/internal/classfile/components/CodeLocalsShifter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public sealed interface CodeLocalsShifter extends CodeTransform {
5757
static CodeLocalsShifter of(AccessFlags methodFlags, MethodTypeDesc methodDescriptor) {
5858
int fixed = methodFlags.has(AccessFlag.STATIC) ? 0 : 1;
5959
for (var param : methodDescriptor.parameterList())
60-
fixed += TypeKind.fromDescriptor(param.descriptorString()).slotSize();
60+
fixed += TypeKind.from(param).slotSize();
6161
return new CodeLocalsShifterImpl(fixed);
6262
}
6363

src/java.base/share/classes/jdk/internal/classfile/components/CodeStackTracker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ public void accept(CodeBuilder cb, CodeElement el) {
235235
case InvokeDynamicInstruction i -> {
236236
var type = i.typeSymbol();
237237
pop(type.parameterCount());
238-
push(TypeKind.fromDescriptor(type.returnType().descriptorString()));
238+
push(TypeKind.from(type.returnType()));
239239
}
240240
case InvokeInstruction i -> {
241241
var type = i.typeSymbol();
242242
pop(type.parameterCount());
243243
if (i.opcode() != Opcode.INVOKESTATIC) pop(1);
244-
push(TypeKind.fromDescriptor(type.returnType().descriptorString()));
244+
push(TypeKind.from(type.returnType()));
245245
}
246246
case LoadInstruction i ->
247247
push(i.typeKind());

src/java.base/share/classes/jdk/internal/classfile/components/snippet-files/PackageSnippets.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ byte[] classInstrumentation(ClassModel target, ClassModel instrumentor, Predicat
173173
if (!mm.flags().has(AccessFlag.STATIC))
174174
storeStack.push(StoreInstruction.of(TypeKind.ReferenceType, slot++));
175175
for (var pt : mm.methodTypeSymbol().parameterList()) {
176-
var tk = TypeKind.fromDescriptor(pt.descriptorString());
176+
var tk = TypeKind.from(pt);
177177
storeStack.push(StoreInstruction.of(tk, slot));
178178
slot += tk.slotSize();
179179
}

src/java.base/share/classes/jdk/internal/classfile/snippet-files/PackageSnippets.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ byte[] classInstrumentation(ClassModel target, ClassModel instrumentor, Predicat
267267
if (!mm.flags().has(AccessFlag.STATIC))
268268
storeStack.add(StoreInstruction.of(TypeKind.ReferenceType, slot++));
269269
for (var pt : mm.methodTypeSymbol().parameterList()) {
270-
var tk = TypeKind.fromDescriptor(pt.descriptorString());
270+
var tk = TypeKind.from(pt);
271271
storeStack.addFirst(StoreInstruction.of(tk, slot));
272272
slot += tk.slotSize();
273273
}

test/jdk/jdk/classfile/AdvancedTransformationsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private static byte[] instrument(ClassModel target, ClassModel instrumentor, Pre
319319
if (!mm.flags().has(AccessFlag.STATIC))
320320
storeStack.push(StoreInstruction.of(TypeKind.ReferenceType, slot++));
321321
for (var pt : mm.methodTypeSymbol().parameterList()) {
322-
var tk = TypeKind.fromDescriptor(pt.descriptorString());
322+
var tk = TypeKind.from(pt);
323323
storeStack.push(StoreInstruction.of(tk, slot));
324324
slot += tk.slotSize();
325325
}

0 commit comments

Comments
 (0)