2
0
Эх сурвалжийг харах

[jvm] support the new JVM constant pool tags (#9564)

Jens Fischer 5 жил өмнө
parent
commit
f6d22aaf65

+ 7 - 0
libs/javalib/jData.ml

@@ -89,7 +89,10 @@ type jconstant =
   (** invokeDynamic-specific *)
   (** invokeDynamic-specific *)
   | ConstMethodHandle of (reference_type * jconstant) (* tag = 15 *)
   | ConstMethodHandle of (reference_type * jconstant) (* tag = 15 *)
   | ConstMethodType of jmethod_signature (* tag = 16 *)
   | ConstMethodType of jmethod_signature (* tag = 16 *)
+  | ConstDynamic of (bootstrap_method * unqualified_name * jsignature) (* tag = 17 *)
   | ConstInvokeDynamic of (bootstrap_method * unqualified_name * jsignature) (* tag = 18 *)
   | ConstInvokeDynamic of (bootstrap_method * unqualified_name * jsignature) (* tag = 18 *)
+  | ConstModule of unqualified_name (* tag = 19 *)
+  | ConstPackage of unqualified_name (* tag = 20 *)
   | ConstUnusable
   | ConstUnusable
 
 
 type jaccess_flag =
 type jaccess_flag =
@@ -110,6 +113,7 @@ type jaccess_flag =
   | JInterface (* 0x0200 *)
   | JInterface (* 0x0200 *)
   | JAbstract (* 0x0400 *)
   | JAbstract (* 0x0400 *)
   | JAnnotation (* 0x2000 *)
   | JAnnotation (* 0x2000 *)
+  | JModule (* 0x8000 *)
   (** method flags *)
   (** method flags *)
   | JBridge (* 0x0040 *)
   | JBridge (* 0x0040 *)
   | JVarArgs (* 0x0080 *)
   | JVarArgs (* 0x0080 *)
@@ -204,7 +208,10 @@ type jconstant_raw =
   | KUtf8String of string (* 1 *)
   | KUtf8String of string (* 1 *)
   | KMethodHandle of (reference_type * dynref) (* 15 *)
   | KMethodHandle of (reference_type * dynref) (* 15 *)
   | KMethodType of utf8ref (* 16 *)
   | KMethodType of utf8ref (* 16 *)
+  | KDynamic of (bootstrapref * nametyperef) (* 17 *)
   | KInvokeDynamic of (bootstrapref * nametyperef) (* 18 *)
   | KInvokeDynamic of (bootstrapref * nametyperef) (* 18 *)
+  | KModule of utf8ref (* 19 *)
+  | KPackage of utf8ref (* 20 *)
   | KUnusable
   | KUnusable
 
 
 (* jData debugging *)
 (* jData debugging *)

+ 16 - 1
libs/javalib/jReader.ml

@@ -87,10 +87,18 @@ let parse_constant max idx ch =
     KMethodHandle (reft, dynref)
     KMethodHandle (reft, dynref)
   | 16 ->
   | 16 ->
     KMethodType (index())
     KMethodType (index())
+  | 17 ->
+    let bootstrapref = read_ui16 ch in (* not index *)
+    let nametyperef = index() in
+    KDynamic (bootstrapref, nametyperef)
   | 18 ->
   | 18 ->
     let bootstrapref = read_ui16 ch in (* not index *)
     let bootstrapref = read_ui16 ch in (* not index *)
     let nametyperef = index() in
     let nametyperef = index() in
     KInvokeDynamic (bootstrapref, nametyperef)
     KInvokeDynamic (bootstrapref, nametyperef)
+  | 19 ->
+    KModule (index())
+  | 20 ->
+    KPackage (index())
   | n ->
   | n ->
     error()
     error()
 
 
@@ -328,9 +336,16 @@ let rec expand_constant consts i =
     ConstMethodHandle (reference_type, expand_constant consts dynref)
     ConstMethodHandle (reference_type, expand_constant consts dynref)
   | KMethodType utf8ref ->
   | KMethodType utf8ref ->
     ConstMethodType (parse_method_signature (expand_string utf8ref))
     ConstMethodType (parse_method_signature (expand_string utf8ref))
+  | KDynamic(bootstrapref, nametyperef) ->
+    let n, t = expand_nametype nametyperef in
+    ConstDynamic(bootstrapref, n, t)
   | KInvokeDynamic (bootstrapref, nametyperef) ->
   | KInvokeDynamic (bootstrapref, nametyperef) ->
     let n, t = expand_nametype nametyperef in
     let n, t = expand_nametype nametyperef in
     ConstInvokeDynamic(bootstrapref, n, t)
     ConstInvokeDynamic(bootstrapref, n, t)
+  | KModule n ->
+    ConstModule (expand_string n)
+  | KPackage n ->
+    ConstPackage (expand_string n)
   | KUnusable ->
   | KUnusable ->
     ConstUnusable
     ConstUnusable
 
 
@@ -543,7 +558,7 @@ let parse_class ch =
       c
       c
   ) in
   ) in
   let consts = Array.mapi (fun i _ -> expand_constant consts i) consts in
   let consts = Array.mapi (fun i _ -> expand_constant consts i) consts in
-  let flags = parse_access_flags ch [JPublic; JUnusable; JUnusable; JUnusable; JFinal; JSuper; JUnusable; JUnusable; JUnusable; JInterface; JAbstract; JUnusable; JSynthetic; JAnnotation; JEnum] in
+  let flags = parse_access_flags ch [JPublic; JUnusable; JUnusable; JUnusable; JFinal; JSuper; JUnusable; JUnusable; JUnusable; JInterface; JAbstract; JUnusable; JSynthetic; JAnnotation; JEnum; JModule] in
   let this = get_class consts ch in
   let this = get_class consts ch in
   let super_idx = read_ui16 ch in
   let super_idx = read_ui16 ch in
   let super = match super_idx with
   let super = match super_idx with

+ 10 - 0
libs/javalib/jWriter.ml

@@ -197,10 +197,20 @@ let rec const ctx c =
     | ConstMethodType jmethod_signature (* tag = 16 *) ->
     | ConstMethodType jmethod_signature (* tag = 16 *) ->
         write_byte ctx.cpool 16;
         write_byte ctx.cpool 16;
         write_ui16 ctx.cpool (const ctx (ConstUtf8 (encode_sig ctx (TMethod jmethod_signature))))
         write_ui16 ctx.cpool (const ctx (ConstUtf8 (encode_sig ctx (TMethod jmethod_signature))))
+    | ConstDynamic (bootstrap_method, unqualified_name, jsignature) (* tag = 17 *) ->
+        write_byte ctx.cpool 17;
+        write_ui16 ctx.cpool bootstrap_method;
+        write_ui16 ctx.cpool (const ctx (ConstNameAndType(unqualified_name, jsignature)))
     | ConstInvokeDynamic (bootstrap_method, unqualified_name, jsignature) (* tag = 18 *) ->
     | ConstInvokeDynamic (bootstrap_method, unqualified_name, jsignature) (* tag = 18 *) ->
         write_byte ctx.cpool 18;
         write_byte ctx.cpool 18;
         write_ui16 ctx.cpool bootstrap_method;
         write_ui16 ctx.cpool bootstrap_method;
         write_ui16 ctx.cpool (const ctx (ConstNameAndType(unqualified_name, jsignature)))
         write_ui16 ctx.cpool (const ctx (ConstNameAndType(unqualified_name, jsignature)))
+    | ConstModule unqualified_name (* tag = 19 *) ->
+        write_byte ctx.cpool 19;
+        write_ui16 ctx.cpool (const ctx (ConstUtf8 (unqualified_name)));
+    | ConstPackage unqualified_name (* tag = 20 *) ->
+        write_byte ctx.cpool 20;
+        write_ui16 ctx.cpool (const ctx (ConstUtf8 (unqualified_name)));
     | ConstUnusable -> assert false);
     | ConstUnusable -> assert false);
     ctx.ccount <- ret + 1;
     ctx.ccount <- ret + 1;
     ret
     ret