From a9c98dbd97e1585c9ed596d6d3bb718db2c6c83e Mon Sep 17 00:00:00 2001 From: ksrini Date: Tue, 19 Feb 2013 16:49:28 -0800 Subject: [PATCH] 8008262: pack200 should support MethodParameters - part 2 Reviewed-by: jrose --- .../com/sun/java/util/jar/pack/Attribute.java | 2 +- .../sun/java/util/jar/pack/BandStructure.java | 6 ++--- .../sun/java/util/jar/pack/PackageReader.java | 2 +- .../com/sun/java/util/jar/pack/bands.cpp | 2 +- .../native/com/sun/java/util/jar/pack/bands.h | 4 ++-- .../com/sun/java/util/jar/pack/unpack.cpp | 4 ++-- test/tools/pack200/AttributeTests.java | 22 +++++++++--------- test/tools/pack200/Utils.java | 23 ++++++++++++++++++- 8 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/share/classes/com/sun/java/util/jar/pack/Attribute.java b/src/share/classes/com/sun/java/util/jar/pack/Attribute.java index f6ff03026..a6033c97b 100644 --- a/src/share/classes/com/sun/java/util/jar/pack/Attribute.java +++ b/src/share/classes/com/sun/java/util/jar/pack/Attribute.java @@ -177,7 +177,7 @@ class Attribute implements Comparable { 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", diff --git a/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java b/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java index fdfb87dc1..1a1ecef90 100644 --- a/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java +++ b/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java @@ -1505,7 +1505,7 @@ class BandStructure { // 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 @@ class BandStructure { 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 }, diff --git a/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java b/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java index 319b87933..df4687b4a 100644 --- a/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java +++ b/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java @@ -1521,7 +1521,7 @@ class PackageReader extends BandStructure { // *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 diff --git a/src/share/native/com/sun/java/util/jar/pack/bands.cpp b/src/share/native/com/sun/java/util/jar/pack/bands.cpp index 8ad5e556c..42340fa5c 100644 --- a/src/share/native/com/sun/java/util/jar/pack/bands.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/bands.cpp @@ -354,7 +354,7 @@ const band_init all_band_inits[] = { 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), diff --git a/src/share/native/com/sun/java/util/jar/pack/bands.h b/src/share/native/com/sun/java/util/jar/pack/bands.h index c555936d0..052cd5d71 100644 --- a/src/share/native/com/sun/java/util/jar/pack/bands.h +++ b/src/share/native/com/sun/java/util/jar/pack/bands.h @@ -214,7 +214,7 @@ enum band_number { 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 @@ enum band_number { #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] diff --git a/src/share/native/com/sun/java/util/jar/pack/unpack.cpp b/src/share/native/com/sun/java/util/jar/pack/unpack.cpp index 4b5e38a0d..9ce030808 100644 --- a/src/share/native/com/sun/java/util/jar/pack/unpack.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/unpack.cpp @@ -2488,7 +2488,7 @@ void unpacker::read_attrs(int attrc, int obj_count) { 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 @@ int unpacker::write_attrs(int attrc, julong indexBits) { 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; diff --git a/test/tools/pack200/AttributeTests.java b/test/tools/pack200/AttributeTests.java index d4a40a90c..6526737b7 100644 --- a/test/tools/pack200/AttributeTests.java +++ b/test/tools/pack200/AttributeTests.java @@ -29,7 +29,7 @@ import java.util.List; 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 @@ public class AttributeTests { 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 diff --git a/test/tools/pack200/Utils.java b/test/tools/pack200/Utils.java index 0e2269822..07a64595e 100644 --- a/test/tools/pack200/Utils.java +++ b/test/tools/pack200/Utils.java @@ -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 @@ class Utils { throw new RuntimeException("jar command failed"); } } + static List repack(File inFile, File outFile, + boolean disableNative, String... extraOpts) { + List 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 { -- GitLab