Java Bytecode Signatures

As part of the compiler for the programming language I'm working on, I came across common signatures in bytecode that I am trying to parse and convert to AST. The parsing algorithm basically works, but there seems to be a special case where the format of these signatures behaves somewhat strangely. Here are a few of these cases:

java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;)V java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;II)V java.lang.Class#getAnnotation: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA; java.lang.Class#getAnnotationsByType: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)[TA; java.lang.Class#getDeclaredAnnotation: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA; java.lang.Class#getDeclaredAnnotationsByType: <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)[TA; java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;)V java.util.Arrays#parallelSort: <T::Ljava/lang/Comparable<-TT;>;>([TT;II)V java.util.Collections#sort: <T::Ljava/lang/Comparable<-TT;>;>(Ljava/util/List<TT;>;)V 

Of all the methods in these classes, these are the only ones that have :: in their signature. My question is what this token does and why it exists.

Edit

I know about :: in Java, but it's something at the Bytecode level.

+4
source share
1 answer

There is a specific syntax that has changed from JSR 14 to indicate common type boundaries.

 variable_name:class_type_bound:interface_type_bounds 

So for your example:

 <T::Ljava/lang/Comparable<-TT;>;> 

What will reflect:

 <T extends Comparable<T>> 

The name of the variable is T , there is no class type binding, so it was omitted, and there was an interface border of type Comparable<T> .

All your examples follow this, but there are many different forms:

 <T:Ljava/lang/Object;>(Ljava/util/Collection<TT;>;)TT; <T::Ljava/lang/Comparable;>(Ljava/util/Collection<TT;>;)TT; <T:Ljava/lang/Object;:Ljava/lang/Comparable;(Ljava/util/Collection<TT;>;)TT; 

A source

+9
source

Source: https://habr.com/ru/post/1271410/


All Articles