Jdec sometimes generates class names matching jcoder keywords or constant values

B. Blaser bsrbnd at gmail.com
Tue Mar 7 17:35:13 UTC 2017


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

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");


More information about the asmtools-dev mailing list