8008262: pack200 should support MethodParameters - part 2
authorksrini
Tue, 19 Feb 2013 16:49:28 -0800
changeset 16013 3569e84e7429
parent 16012 d10572eb1f48
child 16014 3b0464b381cc
8008262: pack200 should support MethodParameters - part 2 Reviewed-by: jrose
jdk/src/share/classes/com/sun/java/util/jar/pack/Attribute.java
jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java
jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java
jdk/src/share/native/com/sun/java/util/jar/pack/bands.cpp
jdk/src/share/native/com/sun/java/util/jar/pack/bands.h
jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
jdk/test/tools/pack200/AttributeTests.java
jdk/test/tools/pack200/Utils.java
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/Attribute.java	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/Attribute.java	Tue Feb 19 16:49:28 2013 -0800
@@ -177,7 +177,7 @@
         define(sd, ATTR_CONTEXT_METHOD, "Synthetic", "");
         define(sd, ATTR_CONTEXT_METHOD, "Deprecated", "");
         define(sd, ATTR_CONTEXT_METHOD, "Exceptions", "NH[RCH]");
-        define(sd, ATTR_CONTEXT_METHOD, "MethodParameters", "NB[RUNHI]");
+        define(sd, ATTR_CONTEXT_METHOD, "MethodParameters", "NB[RUNHFH]");
         //define(sd, ATTR_CONTEXT_METHOD, "Code", "HHNI[B]NH[PHPOHPOHRCNH]NH[RUHNI[B]]");
 
         define(sd, ATTR_CONTEXT_CODE, "StackMapTable",
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java	Tue Feb 19 16:49:28 2013 -0800
@@ -1505,7 +1505,7 @@
     // band for predefine method parameters
     IntBand  method_MethodParameters_NB = method_attr_bands.newIntBand("method_MethodParameters_NB", BYTE1);
     CPRefBand method_MethodParameters_name_RUN = method_attr_bands.newCPRefBand("method_MethodParameters_name_RUN", UNSIGNED5, CONSTANT_Utf8, NULL_IS_OK);
-    IntBand   method_MethodParameters_flag_I = method_attr_bands.newIntBand("method_MethodParameters_flag_I");
+    IntBand   method_MethodParameters_flag_FH = method_attr_bands.newIntBand("method_MethodParameters_flag_FH");
 
     MultiBand class_attr_bands = class_bands.newMultiBand("(class_attr_bands)", UNSIGNED5);
     IntBand class_flags_hi = class_attr_bands.newIntBand("class_flags_hi");
@@ -1776,9 +1776,9 @@
                            new Band[]{
                                 method_MethodParameters_NB,
                                 method_MethodParameters_name_RUN,
-                                method_MethodParameters_flag_I
+                                method_MethodParameters_flag_FH
                            },
-                           "MethodParameters", "NB[RUNHI]");
+                           "MethodParameters", "NB[RUNHFH]");
         assert(attrCodeEmpty == Package.attrCodeEmpty);
         predefineAttribute(X_ATTR_Signature, ATTR_CONTEXT_METHOD,
                            new Band[] { method_Signature_RS },
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java	Tue Feb 19 16:49:28 2013 -0800
@@ -1521,7 +1521,7 @@
         //        *method_Exceptions_RC :UNSIGNED5  (cp_Class)
         //        *method_MethodParameters_NB: BYTE1
         //        *method_MethodParameters_RUN: UNSIGNED5 (cp_Utf8)
-        //        *method_MethodParameters_I:  UNSIGNED5 (flag)
+        //        *method_MethodParameters_FH:  UNSIGNED5 (flag)
         //
         //  code_attr_bands:
         //        *code_flags :UNSIGNED5
--- a/jdk/src/share/native/com/sun/java/util/jar/pack/bands.cpp	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/src/share/native/com/sun/java/util/jar/pack/bands.cpp	Tue Feb 19 16:49:28 2013 -0800
@@ -354,7 +354,7 @@
   BAND_INIT(method_metadata_bands, -1, -1),
   BAND_INIT(method_MethodParameters_NB, BYTE1_spec, 0),
   BAND_INIT(method_MethodParameters_name_RUN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Utf8)),
-  BAND_INIT(method_MethodParameters_flag_I, UNSIGNED5_spec, 0),
+  BAND_INIT(method_MethodParameters_flag_FH, UNSIGNED5_spec, 0),
   BAND_INIT(method_attr_bands, -1, -1),
   BAND_INIT(class_flags_hi, UNSIGNED5_spec, 0),
   BAND_INIT(class_flags_lo, UNSIGNED5_spec, 0),
--- a/jdk/src/share/native/com/sun/java/util/jar/pack/bands.h	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/src/share/native/com/sun/java/util/jar/pack/bands.h	Tue Feb 19 16:49:28 2013 -0800
@@ -214,7 +214,7 @@
     e_method_metadata_bands,
     e_method_MethodParameters_NB,
     e_method_MethodParameters_name_RUN,
-    e_method_MethodParameters_flag_I,
+    e_method_MethodParameters_flag_FH,
     e_method_attr_bands,
 
     e_class_flags_hi,
@@ -393,7 +393,7 @@
 #define method_Signature_RS all_bands[e_method_Signature_RS]
 #define method_MethodParameters_NB all_bands[e_method_MethodParameters_NB]
 #define method_MethodParameters_name_RUN all_bands[e_method_MethodParameters_name_RUN]
-#define method_MethodParameters_flag_I all_bands[e_method_MethodParameters_flag_I]
+#define method_MethodParameters_flag_FH all_bands[e_method_MethodParameters_flag_FH]
 #define method_attr_bands all_bands[e_method_attr_bands]
 #define class_flags_hi all_bands[e_class_flags_hi]
 #define class_flags_lo all_bands[e_class_flags_lo]
--- a/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp	Tue Feb 19 16:49:28 2013 -0800
@@ -2488,7 +2488,7 @@
     method_MethodParameters_NB.readData(count);
     count = method_MethodParameters_NB.getIntTotal();
     method_MethodParameters_name_RUN.readData(count);
-    method_MethodParameters_flag_I.readData(count);
+    method_MethodParameters_flag_FH.readData(count);
     CHECK;
     break;
 
@@ -4431,7 +4431,7 @@
         putu1(count = method_MethodParameters_NB.getByte());
         for (j = 0; j < count; j++) {
           putref(method_MethodParameters_name_RUN.getRefN());
-          putu4(method_MethodParameters_flag_I.getInt());
+          putu2(method_MethodParameters_flag_FH.getInt());
         }
         break;
 
--- a/jdk/test/tools/pack200/AttributeTests.java	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/test/tools/pack200/AttributeTests.java	Tue Feb 19 16:49:28 2013 -0800
@@ -29,7 +29,7 @@
 import static java.nio.file.StandardOpenOption.*;
 /*
  * @test
- * @bug 6746111 8005252
+ * @bug 6746111 8005252 8008262
  * @summary tests various classfile format and attribute handling by pack200
  * @compile -XDignore.symbol.file Utils.java AttributeTests.java
  * @run main AttributeTests
@@ -67,17 +67,17 @@
         File testjarFile = new File(cwd, "test" + Utils.JAR_FILE_EXT);
         Utils.jar("cvf", testjarFile.getName(), javaClassName);
 
-        // pack using --repack
-        File outjarFile = new File(cwd, "out" + Utils.JAR_FILE_EXT);
-        scratch.clear();
-        scratch.add(Utils.getPack200Cmd());
-        scratch.add("--repack");
-        scratch.add("--unknown-attribute=error");
-        scratch.add(outjarFile.getName());
-        scratch.add(testjarFile.getName());
-        Utils.runExec(scratch);
+        // pack using native --repack
+        File nativejarFile = new File(cwd, "out-n" + Utils.JAR_FILE_EXT);
+        Utils.repack(testjarFile, nativejarFile, false,
+                     "--unknown-attribute=error");
+        Utils.doCompareVerify(testjarFile, nativejarFile);
 
-        Utils.doCompareVerify(testjarFile, outjarFile);
+        // pack using java --repack
+        File javajarFile = new File(cwd, "out-j" + Utils.JAR_FILE_EXT);
+        Utils.repack(testjarFile, javajarFile, true,
+                     "--unknown-attribute=error");
+        Utils.doCompareBitWise(nativejarFile, javajarFile);
     }
     /*
      * this test checks to see if we get the expected strings for output
--- a/jdk/test/tools/pack200/Utils.java	Tue Feb 19 15:31:19 2013 -0500
+++ b/jdk/test/tools/pack200/Utils.java	Tue Feb 19 16:49:28 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2013, 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
@@ -314,6 +314,27 @@
             throw new RuntimeException("jar command failed");
         }
     }
+    static List<String> repack(File inFile, File outFile,
+            boolean disableNative, String... extraOpts) {
+        List<String> cmdList = new ArrayList<>();
+        cmdList.clear();
+        cmdList.add(Utils.getJavaCmd());
+        cmdList.add("-ea");
+        cmdList.add("-esa");
+        if (disableNative) {
+            cmdList.add("-Dcom.sun.java.util.jar.pack.disable.native=true");
+        }
+        cmdList.add("com.sun.java.util.jar.pack.Driver");
+        cmdList.add("--repack");
+        if (extraOpts != null) {
+           for (String opt: extraOpts) {
+               cmdList.add(opt);
+           }
+        }
+        cmdList.add(outFile.getName());
+        cmdList.add(inFile.getName());
+        return Utils.runExec(cmdList);
+    }
 
     // given a jar file foo.jar will write to foo.pack
     static void pack(JarFile jarFile, File packFile) throws IOException {