diff options
author | 2015-10-14 16:08:04 +0000 | |
---|---|---|
committer | 2015-10-14 18:29:59 +0000 | |
commit | c4c93891c5107390648318b7564c9fdc690b034a (patch) | |
tree | 90ab307258c28623206dd5ea6d6e80a9f8c71f72 /third_party | |
parent | 8096c4274ac57267dace4166ac05d5665b098d95 (diff) |
Support Java 8 MethodParameters attribute in ijar
--
MOS_MIGRATED_REVID=105417011
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/ijar/classfile.cc | 40 | ||||
-rwxr-xr-x | third_party/ijar/test/ijar_test.sh | 12 | ||||
-rw-r--r-- | third_party/ijar/test/methodparameters/Test.java | 20 |
3 files changed, 69 insertions, 3 deletions
diff --git a/third_party/ijar/classfile.cc b/third_party/ijar/classfile.cc index 0a359d019b..1a11a7b3bf 100644 --- a/third_party/ijar/classfile.cc +++ b/third_party/ijar/classfile.cc @@ -1142,6 +1142,41 @@ struct TypeAnnotationsAttribute : Attribute { std::vector<TypeAnnotation*> type_annotations_; }; +// See JVMS ยง4.7.24 +struct MethodParametersAttribute : Attribute { + static MethodParametersAttribute *Read(const u1 *&p, Constant *attribute_name, + u4 attribute_length) { + auto attr = new MethodParametersAttribute; + attr->attribute_name_ = attribute_name; + u1 parameters_count = get_u1(p); + for (int ii = 0; ii < parameters_count; ++ii) { + MethodParameter* parameter = new MethodParameter; + parameter->name_ = constant(get_u2be(p)); + parameter->access_flags_ = get_u2be(p); + attr->parameters_.push_back(parameter); + } + return attr; + } + + void Write(u1 *&p) { + WriteProlog(p, -1); + u1 *payload_start = p - 4; + put_u1(p, parameters_.size()); + for (MethodParameter* parameter : parameters_) { + put_u2be(p, parameter->name_->slot()); + put_u2be(p, parameter->access_flags_); + } + put_u4be(payload_start, p - 4 - payload_start); // backpatch length + } + + struct MethodParameter { + Constant *name_; + u2 access_flags_; + }; + + std::vector<MethodParameter*> parameters_; +}; + struct GeneralAttribute : Attribute { static GeneralAttribute* Read(const u1 *&p, Constant *attribute_name, u4 attribute_length) { @@ -1344,10 +1379,11 @@ void HasAttrs::ReadAttrs(const u1 *&p) { attribute_length)); } else if (attr_name == "RuntimeVisibleTypeAnnotations" || attr_name == "RuntimeInvisibleTypeAnnotations") { - // JSR 308: annotations on types. JDK 7 has no use for these yet, but the - // Checkers Framework relies on them. attributes.push_back(TypeAnnotationsAttribute::Read(p, attribute_name, attribute_length)); + } else if (attr_name == "MethodParameters") { + attributes.push_back( + MethodParametersAttribute::Read(p, attribute_name, attribute_length)); } else { // Skip over unknown attributes with a warning. The JVM spec // says this is ok, so long as we handle the mandatory attributes. diff --git a/third_party/ijar/test/ijar_test.sh b/third_party/ijar/test/ijar_test.sh index 848dbddd53..174d35cab1 100755 --- a/third_party/ijar/test/ijar_test.sh +++ b/third_party/ijar/test/ijar_test.sh @@ -1,6 +1,6 @@ #!/bin/bash -eu # -# Copyright 2015 Google Inc. All rights reserved. +# Copyright 2015 The Bazel Authors. 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 @@ -66,6 +66,8 @@ TYPEANN2_IJAR=$TEST_TMPDIR/typeannotations2_interface.jar TYPEANN2_JAVA=$IJAR_SRCDIR/test/TypeAnnotationTest2.java 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 #### Setup @@ -494,4 +496,12 @@ EOF cmp one/one-ijar.jar three/three-ijar.jar } +function test_method_parameters_attribute() { + # Check that Java 8 MethodParameters attributes are preserved + $IJAR $METHODPARAM_JAR $METHODPARAM_IJAR || fail "ijar failed" + $JAVAP -classpath $METHODPARAM_IJAR -v methodparameters.Test >& $TEST_log \ + || fail "javap failed" + expect_log "MethodParameters" "MethodParameters not preserved!" +} + run_suite "ijar tests" diff --git a/third_party/ijar/test/methodparameters/Test.java b/third_party/ijar/test/methodparameters/Test.java new file mode 100644 index 0000000000..7843cd8a7c --- /dev/null +++ b/third_party/ijar/test/methodparameters/Test.java @@ -0,0 +1,20 @@ +// Copyright 2015 The Bazel Authors. 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 methodparameters; + +public class Test { + public static void foo(String fooParam) {} + public static void bar(final String barParam) {} +} |