You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2014/04/19 00:09:59 UTC
svn commit: r1588579 - in /commons/proper/bcel/trunk/src:
main/java/org/apache/bcel/ main/java/org/apache/bcel/classfile/
main/java/org/apache/bcel/verifier/statics/
test/java/org/apache/bcel/visitors/
Author: ebourg
Date: Fri Apr 18 22:09:58 2014
New Revision: 1588579
URL: http://svn.apache.org/r1588579
Log:
Added the BootstrapMethods attribute defined in the class format 51 (Java 7)
Added:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java (with props)
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java (with props)
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/Constants.java Fri Apr 18 22:09:58 2014
@@ -1444,8 +1444,9 @@ public interface Constants {
public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE = 17;
public static final byte ATTR_ENCLOSING_METHOD = 18;
public static final byte ATTR_STACK_MAP_TABLE = 19;
+ public static final byte ATTR_BOOTSTRAP_METHODS = 20;
- public static final short KNOWN_ATTRIBUTES = 20;
+ public static final short KNOWN_ATTRIBUTES = 21;
// TOFO: FIXXXXX
public static final String[] ATTRIBUTE_NAMES = {
@@ -1455,7 +1456,8 @@ public interface Constants {
"PMGClass", "Signature", "StackMap",
"RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
"RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations",
- "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable"
+ "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable",
+ "BootstrapMethods"
};
/** Constants used in the StackMap attribute.
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Attribute.java Fri Apr 18 22:09:58 2014
@@ -214,6 +214,8 @@ public abstract class Attribute implemen
return new EnclosingMethod(name_index, length, file, constant_pool);
case Constants.ATTR_STACK_MAP_TABLE:
return new StackMapTable(name_index, length, file, constant_pool);
+ case Constants.ATTR_BOOTSTRAP_METHODS:
+ return new BootstrapMethods(name_index, length, file, constant_pool);
default: // Never reached
throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
}
Added: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java?rev=1588579&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java (added)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java Fri Apr 18 22:09:58 2014
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.bcel.classfile;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * Entry of the bootstrap_methods table.
+ *
+ * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.23">The class File Format : The BootstrapMethods Attribute</a>
+ * @since 6.0
+ */
+public class BootstrapMethod implements Serializable, Cloneable {
+
+ private static final long serialVersionUID = -4517534834047695344L;
+
+ /** Index of the CONSTANT_MethodHandle_info structure in the constant_pool table */
+ private int bootstrap_method_ref;
+
+ /** Array of references to the constant_pool table */
+ private int[] bootstrap_arguments;
+
+ public BootstrapMethod() {
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param file Input stream
+ * @throws IOException
+ * @throws ClassFormatException
+ */
+ BootstrapMethod(DataInputStream file) throws IOException, ClassFormatException {
+ bootstrap_method_ref = file.readUnsignedShort();
+
+ int num_bootstrap_methods = file.readUnsignedShort();
+
+ bootstrap_arguments = new int[num_bootstrap_methods];
+ for (int i = 0; i < num_bootstrap_methods; i++) {
+ bootstrap_arguments[i] = file.readUnsignedShort();
+ }
+ }
+
+ public int getBootstrapMethodRef() {
+ return bootstrap_method_ref;
+ }
+
+ public void setBootstrapMethodRef(int bootstrap_method_ref) {
+ this.bootstrap_method_ref = bootstrap_method_ref;
+ }
+
+ public int[] getBootstrapArguments() {
+ return bootstrap_arguments;
+ }
+
+ public void setBootstrapArguments(int[] bootstrap_arguments) {
+ this.bootstrap_arguments = bootstrap_arguments;
+ }
+
+ /**
+ * Dump object to file stream on binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump(DataOutputStream file) throws IOException {
+ file.writeShort(bootstrap_method_ref);
+ file.writeShort(bootstrap_arguments.length);
+ for (int bootstrap_argument : bootstrap_arguments) {
+ file.writeShort(bootstrap_argument);
+ }
+ }
+
+ /**
+ * @return deep copy of this object
+ */
+ public BootstrapMethod copy() {
+ try {
+ return (BootstrapMethod) clone();
+ } catch (CloneNotSupportedException e) {
+ }
+ return null;
+ }
+}
Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java?rev=1588579&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java (added)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java Fri Apr 18 22:09:58 2014
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.bcel.classfile;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Constants;
+
+/**
+ * This class represents a BootstrapMethods attribute.
+ *
+ * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.23">The class File Format : The BootstrapMethods Attribute</a>
+ * @since 6.0
+ */
+public class BootstrapMethods extends Attribute {
+
+ private static final long serialVersionUID = -2169230245012340809L;
+
+ private BootstrapMethod[] bootstrap_methods;
+
+ public BootstrapMethods(int name_index, int length, BootstrapMethod[] bootstrap_methods, ConstantPool constant_pool) {
+ super(Constants.ATTR_BOOTSTRAP_METHODS, name_index, length, constant_pool);
+ this.bootstrap_methods = bootstrap_methods;
+ }
+
+ BootstrapMethods(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (BootstrapMethod[]) null, constant_pool);
+
+ int num_bootstrap_methods = file.readUnsignedShort();
+ bootstrap_methods = new BootstrapMethod[num_bootstrap_methods];
+ for (int i = 0; i < num_bootstrap_methods; i++) {
+ bootstrap_methods[i] = new BootstrapMethod(file);
+ }
+ }
+
+ public final BootstrapMethod[] getBootstrapMethods() {
+ return bootstrap_methods;
+ }
+
+ public final void setBootstrapMethods(BootstrapMethod[] bootstrap_methods) {
+ this.bootstrap_methods = bootstrap_methods;
+ }
+
+ @Override
+ public void accept(Visitor v) {
+ v.visitBootstrapMethods(this);
+ }
+
+ @Override
+ public BootstrapMethods copy(ConstantPool _constant_pool) {
+ BootstrapMethods c = (BootstrapMethods) clone();
+ c.bootstrap_methods = new BootstrapMethod[bootstrap_methods.length];
+
+ for (int i = 0; i < bootstrap_methods.length; i++) {
+ c.bootstrap_methods[i] = bootstrap_methods[i].copy();
+ }
+ c.constant_pool = _constant_pool;
+ return c;
+ }
+
+ /**
+ * Dump bootstrap methods attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+
+ file.writeShort(bootstrap_methods.length);
+ for (BootstrapMethod bootstrap_method : bootstrap_methods) {
+ bootstrap_method.dump(file);
+ }
+ }
+}
Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java Fri Apr 18 22:09:58 2014
@@ -430,4 +430,11 @@ public class DescendingVisitor implement
obj.accept(visitor);
stack.pop();
}
+
+ public void visitBootstrapMethods(BootstrapMethods obj)
+ {
+ stack.push(obj);
+ obj.accept(visitor);
+ stack.pop();
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java Fri Apr 18 22:09:58 2014
@@ -189,4 +189,8 @@ public class EmptyVisitor implements Vis
public void visitLocalVariableTypeTable(LocalVariableTypeTable obj)
{
}
+
+ public void visitBootstrapMethods(BootstrapMethods obj)
+ {
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Visitor.java Fri Apr 18 22:09:58 2014
@@ -106,4 +106,6 @@ public interface Visitor
void visitLocalVariableTypeTable(LocalVariableTypeTable obj);
void visitEnclosingMethod(EnclosingMethod obj);
+
+ void visitBootstrapMethods(BootstrapMethods obj);
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java Fri Apr 18 22:09:58 2014
@@ -19,6 +19,7 @@ package org.apache.bcel.verifier.statics
import org.apache.bcel.classfile.Annotations;
+import org.apache.bcel.classfile.BootstrapMethods;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.CodeException;
import org.apache.bcel.classfile.ConstantClass;
@@ -296,4 +297,9 @@ public class StringRepresentation extend
public void visitUnknown(Unknown obj) {
tostring = toString(obj);
}
+
+ @Override
+ public void visitBootstrapMethods(BootstrapMethods obj) {
+ tostring = toString(obj);
+ }
}
Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java?rev=1588579&r1=1588578&r2=1588579&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/visitors/CounterVisitor.java Fri Apr 18 22:09:58 2014
@@ -21,6 +21,7 @@ package org.apache.bcel.visitors;
import org.apache.bcel.classfile.AnnotationDefault;
import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.Annotations;
+import org.apache.bcel.classfile.BootstrapMethods;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.CodeException;
import org.apache.bcel.classfile.ConstantClass;
@@ -141,6 +142,8 @@ public class CounterVisitor implements V
public int stackMapTableCount = 0;
public int stackMapTableEntryCount = 0;
+
+ public int bootstrapMethodsCount = 0;
public void visitAnnotation(Annotations obj)
@@ -333,11 +336,18 @@ public class CounterVisitor implements V
unknownCount++;
}
- public void visitStackMapTable(StackMapTable obj) {
+ public void visitStackMapTable(StackMapTable obj)
+ {
stackMapTableCount++;
}
- public void visitStackMapTableEntry(StackMapTableEntry obj) {
+ public void visitStackMapTableEntry(StackMapTableEntry obj)
+ {
stackMapTableEntryCount++;
}
+
+ public void visitBootstrapMethods(BootstrapMethods obj)
+ {
+ bootstrapMethodsCount++;
+ }
}