Jdec sometimes generates class names matching jcoder keywords or constant values

Kevin Looney kevin.looney at oracle.com
Mon Aug 28 19:50:08 UTC 2017


Hello Bernard,

Sorry for the delay in responding.   Our engineers tasked with updates 
on assembler tools have been working on critical changes for JDK 9 
(including module support).  They intend to veryify your patch and 
update AsmTools after they finish this JDK 9 support.

Hope this helps,
Kevin L

On 8/25/17 12:35 AM, B. Blaser wrote:
> Hi,
>
> On 7 March 2017 at 18:35, B. Blaser <bsrbnd at gmail.com> wrote:
>> Hi,
>> Any comment about that?
>>
>> I think this is what the specification claims here:
>>
>> https://wiki.openjdk.java.net/display/CodeTools/Chapter+2#Chapter2-AssemblersandDissassemblers
> Should I create a JBS issue for that?
>
> Bernard
>
>> Note also the small spelling mistake in the title: Dis(s)assemblers
>>
>> Thanks,
>> Bernard
>>
>> 2017-02-20 15:06 GMT+01:00 B. Blaser <bsrbnd at gmail.com>:
>>> Hi,
>>>
>>> Jdec sometimes generates class names matching jcoder keywords or
>>> constant values, for example:
>>>
>>> $ cat Method.java I.java z.java
>>> // JcodTokens.ConstType.CONSTANT_METHOD
>>> class Method {}
>>>
>>> // Tables.StackMapType.ITEM_Integer
>>> interface I {}
>>>
>>> // JcodTokens.Token.ZEROINDEX
>>> class z {}
>>>
>>> $ javac Method.java I.java z.java
>>> $ java -jar asmtools.jar jdec Method.class > Method.jcod
>>> $ java -jar asmtools.jar jcoder Method.jcod
>>> org.openjdk.asmtools.jcoder.SyntaxError
>>>      [...]
>>> Method.jcod:1: Name expected.
>>> class Method {
>>>       ^
>>> 1 error
>>>
>>> $ java -jar asmtools.jar jdec I.class > I.jcod
>>> $ java -jar asmtools.jar jcoder I.jcod
>>> org.openjdk.asmtools.jcoder.SyntaxError
>>>      [...]
>>> I.jcod:1: Name expected.
>>> class I {
>>>       ^
>>> 1 error
>>>
>>> $ java -jar asmtools.jar jdec z.class > z.jcod
>>> $ java -jar asmtools.jar jcoder z.jcod
>>> org.openjdk.asmtools.jcoder.SyntaxError
>>>      [...]
>>> z.jcod:1: Name expected.
>>> class z {
>>>       ^
>>> 1 error
>>>
>>> The fix below (ClassData.decodeClass()) makes jdec print the file name
>>> instead of the class name when the latter matches a jcoder keyword or
>>> constant value.
>>>
>>> Any comment or review is welcome.
>>>
>>> Thanks,
>>> Bernard
>>>
>>> diff --git a/src/org/openjdk/asmtools/jcoder/JcodTokens.java
>>> b/src/org/openjdk/asmtools/jcoder/JcodTokens.java
>>> --- a/src/org/openjdk/asmtools/jcoder/JcodTokens.java
>>> +++ b/src/org/openjdk/asmtools/jcoder/JcodTokens.java
>>> @@ -1,5 +1,5 @@
>>>   /*
>>> - * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
>>> + * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
>>>    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>>    *
>>>    * This code is free software; you can redistribute it and/or modify it
>>> @@ -368,7 +368,7 @@
>>>           ConstantTypes.put(tt.value, tt);
>>>       }
>>>
>>> -    static int constValue(String stringValue) {
>>> +    public static int constValue(String stringValue) {
>>>           ConstType Val = constType(stringValue);
>>>           int val = -1;
>>>
>>> diff --git a/src/org/openjdk/asmtools/jdec/ClassData.java
>>> b/src/org/openjdk/asmtools/jdec/ClassData.java
>>> --- a/src/org/openjdk/asmtools/jdec/ClassData.java
>>> +++ b/src/org/openjdk/asmtools/jdec/ClassData.java
>>> @@ -1,5 +1,5 @@
>>>   /*
>>> - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
>>> + * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
>>>    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>>    *
>>>    * This code is free software; you can redistribute it and/or modify it
>>> @@ -24,6 +24,7 @@
>>>
>>>   import org.openjdk.asmtools.jasm.Modifiers;
>>>   import org.openjdk.asmtools.util.I18NResourceBundle;
>>> +import org.openjdk.asmtools.jcoder.JcodTokens;
>>>
>>>   import java.io.*;
>>>
>>> @@ -956,7 +957,15 @@
>>>                       entityname = "module";
>>>                       classname = classname.substring(0, --ind < 0 ? 0
>>> : ind ).replace('/', '.');
>>>                   }
>>> -                out_begin(String.format("%s %s {", entityname, classname));
>>> +                if (JcodTokens.keyword_token_ident(classname) !=
>>> JcodTokens.Token.IDENT ||
>>> +                        JcodTokens.constValue(classname) != -1) {
>>> +                    // Jcod can't parse a classname matching a
>>> keyword or a constant value,
>>> +                    // then use the filename instead:
>>> +                    out_begin(String.format("file \"%s.class\" {", classname));
>>> +                }
>>> +                else {
>>> +                    out_begin(String.format("%s %s {", entityname, classname));
>>> +                }
>>>               } catch (Exception e) {
>>>                   classname = inpname;
>>>                   out.println("// " + e.getMessage() + " while
>>> accessing classname");


-- 
kevin.looney at oracle.com



More information about the asmtools-dev mailing list