[PATCH][asmtools] Fix incorrect handling of some CPX2 constant pool entries by JDIS (original) (raw)

Maxim Degtyarev mdegtyarev at gmail.com
Mon Mar 12 23:52:50 UTC 2018


The proposed patch (see attached file jdis-cpx2-bug.diff.txt) address incorrect handling of some constant pool entries represented with CPX2 class by ASMTOOLS JDIS.

JDIS incorrectly assume that field CPX2::value1 is always used to hold index of constant pool entry of type CONSTANT_CLASS. This assumption is valid only for entries of type CONSTANT_FIELD, CONSTANT_METHOD and CONSTANT_INTERFACEMETHOD. For CONSTANT_NAMEANDTYPE, CONSTANT_METHODHANDLE, CONSTANT_DYNAMIC and CONSTANT_INVOKEDYNAMIC this assumption is wrong. As a result asmtools jdis may produce malformed output for valid input.

Example:

public class Test {

// Force `class Test` entry appear in the constant pool before

InvokeDynamic entries. public Class<?> CLASS = Test.class;

private static Runnable[] workers = {
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test"),
    () -> System.out.println("Test")
};

public static void main(String... args) {

    for(Runnable worker : workers) {
        worker.run();
    }

}

}

One of invokedynamic instructions may be rendered by jdis as

    invokedynamic    InvokeDynamic run:"()Ljava/lang/Runnable;";

instead of

    invokedynamic    InvokeDynamic

REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;":run:"()Ljava/lang/Runnable;" MethodType "()V", MethodHandle REF_invokeStatic:Test.lambda$static$1:"()V", MethodType "()V"; -------------- next part --------------

HG changeset patch

User maccimo

Date 1520880268 -10800

Mon Mar 12 21:44:28 2018 +0300

Node ID f5e62b0fae745f3640455513a9824c1d3a59e1be

Parent 2904229ed97ec1d90a055ad86759f867cdc5296b

Fix incorrect handling of constant pool entries of type CONSTANT_NAMEANDTYPE, CONSTANT_METHODHANDLE, CONSTANT_DYNAMIC and CONSTANT_INVOKEDYNAMIC.

diff --git a/src/org/openjdk/asmtools/jdis/ConstantPool.java b/src/org/openjdk/asmtools/jdis/ConstantPool.java --- a/src/org/openjdk/asmtools/jdis/ConstantPool.java +++ b/src/org/openjdk/asmtools/jdis/ConstantPool.java @@ -500,8 +500,9 @@ * CPX2 * * Constant entries that contain two constant-pool indices. Usually, this includes:

@@ -674,6 +692,8 @@ case CONSTANT_FIELD: case CONSTANT_METHOD: case CONSTANT_INTERFACEMETHOD:

@@ -845,13 +865,13 @@ * * getClassName *

@@ -998,17 +1018,10 @@ if (cns == null) { return "#" + cpx; }



More information about the code-tools-dev mailing list