aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Liam Miller-Cushon <cushon@google.com>2015-10-19 17:13:48 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-10-20 16:35:48 +0000
commit6e771dbd6979132a77654b7b5335f3d7273ff4c6 (patch)
treee6b0f91229185cee39e3d49ac0776db09332affe
parent880827312919e5829ab056b3f27284e24c2411c2 (diff)
Recognize SourceDebugExtension attributes in ijar
This doesn't change behaviour (they continue to get dropped from the interface jar), but it avoids some spurious "skipping unknown attribute" warnings. -- MOS_MIGRATED_REVID=105767979
-rw-r--r--third_party/ijar/classfile.cc4
-rw-r--r--third_party/ijar/test/BUILD16
-rw-r--r--third_party/ijar/test/GenSourceDebugExtension.java84
-rwxr-xr-xthird_party/ijar/test/ijar_test.sh13
4 files changed, 116 insertions, 1 deletions
diff --git a/third_party/ijar/classfile.cc b/third_party/ijar/classfile.cc
index 1a11a7b3bf..1e88688890 100644
--- a/third_party/ijar/classfile.cc
+++ b/third_party/ijar/classfile.cc
@@ -1341,12 +1341,14 @@ void HasAttrs::ReadAttrs(const u1 *&p) {
std::string attr_name = attribute_name->Display();
if (attr_name == "SourceFile" ||
+ attr_name == "StackMapTable" ||
attr_name == "LineNumberTable" ||
attr_name == "LocalVariableTable" ||
attr_name == "LocalVariableTypeTable" ||
attr_name == "Code" ||
attr_name == "Synthetic" ||
- attr_name == "BootstrapMethods") {
+ attr_name == "BootstrapMethods" ||
+ attr_name == "SourceDebugExtension") {
p += attribute_length; // drop these attributes
} else if (attr_name == "Exceptions") {
attributes.push_back(ExceptionsAttribute::Read(p, attribute_name));
diff --git a/third_party/ijar/test/BUILD b/third_party/ijar/test/BUILD
index cb0652ffc1..05bca7c100 100644
--- a/third_party/ijar/test/BUILD
+++ b/third_party/ijar/test/BUILD
@@ -30,6 +30,7 @@ sh_test(
"WellCompressed2.java",
":libtypeannotations2.jar",
":libmethodparameters.jar",
+ ":source_debug_extension.jar",
"TypeAnnotationTest2.java",
# invokedynamic/ClassWithLambda.java, compiled with javac8
":libinvokedynamic.jar",
@@ -107,6 +108,21 @@ java_library(
javacopts = ["-source 8 -target 8 -parameters"],
)
+java_binary(
+ name = "gen_source_debug_extension",
+ srcs = ["GenSourceDebugExtension.java"],
+ main_class = "test.GenSourceDebugExtension",
+ deps = ["//third_party:asm"],
+)
+
+genrule(
+ name = "gen_source_debug_extension_jar",
+ srcs = [],
+ outs = ["source_debug_extension.jar"],
+ cmd = "$(location :gen_source_debug_extension) $@",
+ tools = ["gen_source_debug_extension"],
+)
+
java_test(
name = "IjarTests",
size = "small",
diff --git a/third_party/ijar/test/GenSourceDebugExtension.java b/third_party/ijar/test/GenSourceDebugExtension.java
new file mode 100644
index 0000000000..055c3eb78d
--- /dev/null
+++ b/third_party/ijar/test/GenSourceDebugExtension.java
@@ -0,0 +1,84 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package test;
+
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
+
+public class GenSourceDebugExtension {
+ public static void main(String[] args) throws IOException {
+ try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(args[0]))) {
+ jos.putNextEntry(new ZipEntry("sourcedebugextension/Test.class"));
+ jos.write(dump());
+ }
+ }
+
+ public static byte[] dump() {
+ ClassWriter cw = new ClassWriter(0);
+ MethodVisitor mv;
+
+ cw.visit(
+ 52,
+ Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
+ "sourcedebugextension/Test",
+ null,
+ "java/lang/Object",
+ null);
+
+ // This is the important part for the test - it's an example SourceDebugExtension found
+ // in Clojure.
+ cw.visitSource(
+ "dispatch.clj",
+ "SMAP\ndispatch.java\nClojure\n*S Clojure\n*F\n+ 1 dispatch.clj\nclojure/pprint/dispatch.clj\n*L\n144#1,8:144\n*E");
+
+ {
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(
+ Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
+ "main",
+ "([Ljava/lang/String;)V",
+ null,
+ null);
+ mv.visitCode();
+ mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
+ mv.visitLdcInsn("Hello");
+ mv.visitMethodInsn(
+ Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(2, 1);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
+
+ return cw.toByteArray();
+ }
+}
diff --git a/third_party/ijar/test/ijar_test.sh b/third_party/ijar/test/ijar_test.sh
index 174d35cab1..6f1a241df9 100755
--- a/third_party/ijar/test/ijar_test.sh
+++ b/third_party/ijar/test/ijar_test.sh
@@ -68,6 +68,8 @@ INVOKEDYNAMIC_JAR=$IJAR_SRCDIR/test/libinvokedynamic.jar
INVOKEDYNAMIC_IJAR=$TEST_TMPDIR/invokedynamic_interface.jar
METHODPARAM_JAR=$IJAR_SRCDIR/test/libmethodparameters.jar
METHODPARAM_IJAR=$TEST_TMPDIR/methodparameters_interface.jar
+SOURCEDEBUGEXT_JAR=$IJAR_SRCDIR/test/source_debug_extension.jar
+SOURCEDEBUGEXT_IJAR=$TEST_TMPDIR/source_debug_extension.jar
#### Setup
@@ -504,4 +506,15 @@ function test_method_parameters_attribute() {
expect_log "MethodParameters" "MethodParameters not preserved!"
}
+function test_source_debug_extension_attribute() {
+ # Check that SourceDebugExtension attributes are dropped without a warning
+ $IJAR $SOURCEDEBUGEXT_JAR $SOURCEDEBUGEXT_IJAR >& $TEST_log || fail "ijar failed"
+ expect_not_log "skipping unknown attribute"
+ $JAVAP -classpath $SOURCEDEBUGEXT_IJAR -v sourcedebugextension.Test >& $TEST_log \
+ || fail "javap failed"
+ expect_not_log "SourceDebugExtension" "SourceDebugExtension preserved!"
+}
+
+SOURCEDEBUGEXT_JAR=$IJAR_SRCDIR/test/source_debug_extension.jar
+
run_suite "ijar tests"