55import java .lang .classfile .MethodModel ;
66import java .lang .classfile .Opcode ;
77import java .lang .classfile .TypeKind ;
8- import java .lang .classfile .attribute .StackMapFrameInfo ;
98import java .lang .classfile .attribute .CodeAttribute ;
9+ import java .lang .classfile .attribute .StackMapFrameInfo ;
1010import java .lang .classfile .constantpool .ClassEntry ;
1111import java .lang .classfile .instruction .ArrayLoadInstruction ;
1212import java .lang .classfile .instruction .ArrayStoreInstruction ;
@@ -77,7 +77,8 @@ Optional<TargetRef.ArrayComponent> arrayComponentTarget(int arrayRefDepthFromTop
7777 return Optional .empty ();
7878 }
7979
80- return Optional .of (new TargetRef .ArrayComponent (arrayRef .descriptor (), arrayRef .sourceTarget ()));
80+ return Optional .of (
81+ new TargetRef .ArrayComponent (arrayRef .descriptor (), arrayRef .sourceTarget ()));
8182 }
8283
8384 void acceptInstruction (java .lang .classfile .Instruction instruction ) {
@@ -91,18 +92,25 @@ void acceptInstruction(java.lang.classfile.Instruction instruction) {
9192 case StoreInstruction store -> simulateStore (store );
9293 case ConstantInstruction constant -> simulateConstant (constant );
9394 case FieldInstruction field -> simulateField (field );
94- case InvokeInstruction invoke -> simulateInvoke (invoke .typeSymbol (), hasReceiver (invoke .opcode ()), invokeReturnSource (invoke ));
95- case InvokeDynamicInstruction invokeDynamic -> simulateInvoke (invokeDynamic .typeSymbol (), false , null );
95+ case InvokeInstruction invoke ->
96+ simulateInvoke (
97+ invoke .typeSymbol (), hasReceiver (invoke .opcode ()), invokeReturnSource (invoke ));
98+ case InvokeDynamicInstruction invokeDynamic ->
99+ simulateInvoke (invokeDynamic .typeSymbol (), false , null );
96100 case ArrayLoadInstruction arrayLoad -> simulateArrayLoad (arrayLoad );
97101 case ArrayStoreInstruction ignored -> simulateArrayStore ();
98102 case TypeCheckInstruction typeCheck -> simulateTypeCheck (typeCheck );
99103 case NewObjectInstruction newObject ->
100- currentState .push (TrackedValue .reference (newObject .className ().asSymbol ().descriptorString (), null ));
101- case NewReferenceArrayInstruction newReferenceArray -> simulateNewReferenceArray (newReferenceArray );
102- case NewPrimitiveArrayInstruction newPrimitiveArray -> simulateNewPrimitiveArray (newPrimitiveArray );
104+ currentState .push (
105+ TrackedValue .reference (newObject .className ().asSymbol ().descriptorString (), null ));
106+ case NewReferenceArrayInstruction newReferenceArray ->
107+ simulateNewReferenceArray (newReferenceArray );
108+ case NewPrimitiveArrayInstruction newPrimitiveArray ->
109+ simulateNewPrimitiveArray (newPrimitiveArray );
103110 case NewMultiArrayInstruction newMultiArray -> simulateNewMultiArray (newMultiArray );
104111 case ConvertInstruction convert -> simulateConvert (convert );
105- case IncrementInstruction increment -> currentState .store (increment .slot (), TrackedValue .primitive (TypeKind .INT ));
112+ case IncrementInstruction increment ->
113+ currentState .store (increment .slot (), TrackedValue .primitive (TypeKind .INT ));
106114 case OperatorInstruction operator -> simulateOperator (operator );
107115 case StackInstruction stackInstruction -> simulateStack (stackInstruction .opcode ());
108116 case BranchInstruction branch -> simulateBranch (branch );
@@ -175,8 +183,7 @@ private void simulateConstant(ConstantInstruction constant) {
175183 private void simulateField (FieldInstruction field ) {
176184 String descriptor = field .typeSymbol ().descriptorString ();
177185 TargetRef .Field sourceTarget =
178- new TargetRef .Field (
179- field .owner ().asInternalName (), field .name ().stringValue (), descriptor );
186+ new TargetRef .Field (field .owner ().asInternalName (), field .name ().stringValue (), descriptor );
180187
181188 switch (field .opcode ()) {
182189 case GETSTATIC -> currentState .push (TrackedValue .fromDescriptor (descriptor , sourceTarget ));
@@ -234,7 +241,8 @@ private void simulateTypeCheck(TypeCheckInstruction typeCheck) {
234241 }
235242
236243 if (typeCheck .opcode () == Opcode .CHECKCAST ) {
237- currentState .push (TrackedValue .reference (typeCheck .type ().asSymbol ().descriptorString (), null ));
244+ currentState .push (
245+ TrackedValue .reference (typeCheck .type ().asSymbol ().descriptorString (), null ));
238246 return ;
239247 }
240248
@@ -280,8 +288,22 @@ private void simulateOperator(OperatorInstruction operator) {
280288 currentState .pop ();
281289 currentState .push (TrackedValue .primitive (operator .typeKind ()));
282290 }
283- case IADD , ISUB , IMUL , IDIV , IREM , IAND , IOR , IXOR , ISHL , ISHR , IUSHR ,
284- FADD , FSUB , FMUL , FDIV , FREM -> {
291+ case IADD ,
292+ ISUB ,
293+ IMUL ,
294+ IDIV ,
295+ IREM ,
296+ IAND ,
297+ IOR ,
298+ IXOR ,
299+ ISHL ,
300+ ISHR ,
301+ IUSHR ,
302+ FADD ,
303+ FSUB ,
304+ FMUL ,
305+ FDIV ,
306+ FREM -> {
285307 currentState .pop ();
286308 currentState .pop ();
287309 currentState .push (TrackedValue .primitive (operator .typeKind ()));
@@ -469,8 +491,14 @@ private void simulateDup2X2() {
469491 private void simulateBranch (BranchInstruction branch ) {
470492 switch (branch .opcode ()) {
471493 case IFEQ , IFNE , IFLT , IFGE , IFGT , IFLE , IFNULL , IFNONNULL -> currentState .pop ();
472- case IF_ICMPEQ , IF_ICMPNE , IF_ICMPLT , IF_ICMPGE , IF_ICMPGT , IF_ICMPLE ,
473- IF_ACMPEQ , IF_ACMPNE -> {
494+ case IF_ICMPEQ ,
495+ IF_ICMPNE ,
496+ IF_ICMPLT ,
497+ IF_ICMPGE ,
498+ IF_ICMPGT ,
499+ IF_ICMPLE ,
500+ IF_ACMPEQ ,
501+ IF_ACMPNE -> {
474502 currentState .pop ();
475503 currentState .pop ();
476504 }
@@ -526,7 +554,9 @@ private boolean hasReceiver(Opcode opcode) {
526554 }
527555
528556 private TrackedValue componentValue (TrackedValue arrayRef ) {
529- if (arrayRef == null || arrayRef .descriptor () == null || !arrayRef .descriptor ().startsWith ("[" )) {
557+ if (arrayRef == null
558+ || arrayRef .descriptor () == null
559+ || !arrayRef .descriptor ().startsWith ("[" )) {
530560 return TrackedValue .reference (null , null );
531561 }
532562
@@ -607,10 +637,14 @@ private static TrackedValue fromVerificationType(
607637 StackMapFrameInfo .VerificationTypeInfo typeInfo , String ownerInternalName ) {
608638 return switch (typeInfo ) {
609639 case StackMapFrameInfo .SimpleVerificationTypeInfo .TOP -> null ;
610- case StackMapFrameInfo .SimpleVerificationTypeInfo .INTEGER -> TrackedValue .primitive (TypeKind .INT );
611- case StackMapFrameInfo .SimpleVerificationTypeInfo .FLOAT -> TrackedValue .primitive (TypeKind .FLOAT );
612- case StackMapFrameInfo .SimpleVerificationTypeInfo .LONG -> TrackedValue .primitive (TypeKind .LONG );
613- case StackMapFrameInfo .SimpleVerificationTypeInfo .DOUBLE -> TrackedValue .primitive (TypeKind .DOUBLE );
640+ case StackMapFrameInfo .SimpleVerificationTypeInfo .INTEGER ->
641+ TrackedValue .primitive (TypeKind .INT );
642+ case StackMapFrameInfo .SimpleVerificationTypeInfo .FLOAT ->
643+ TrackedValue .primitive (TypeKind .FLOAT );
644+ case StackMapFrameInfo .SimpleVerificationTypeInfo .LONG ->
645+ TrackedValue .primitive (TypeKind .LONG );
646+ case StackMapFrameInfo .SimpleVerificationTypeInfo .DOUBLE ->
647+ TrackedValue .primitive (TypeKind .DOUBLE );
614648 case StackMapFrameInfo .SimpleVerificationTypeInfo .NULL -> TrackedValue .reference (null , null );
615649 case StackMapFrameInfo .SimpleVerificationTypeInfo .UNINITIALIZED_THIS ->
616650 TrackedValue .reference ("L" + ownerInternalName + ";" , null );
0 commit comments