41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the copyright holders nor the names of its 44 * contributors may be used to endorse or promote products derived from 45 * this software without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 51 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 57 * THE POSSIBILITY OF SUCH DAMAGE. 58 */ 59 package jdk.internal.org.objectweb.asm; 60 61 /** 62 * A non standard class, field, method or code attribute. 63 * 64 * @author Eric Bruneton 65 * @author Eugene Kuleshov 66 */ 67 public class Attribute { 68 69 /** 70 * The type of this attribute. 71 */ 72 public final String type; 73 74 /** 75 * The raw value of this attribute, used only for unknown attributes. 76 */ 77 byte[] value; 78 79 /** 80 * The next attribute in this attribute list. May be <tt>null</tt>. 264 * the maximum stack size of the method corresponding to these 265 * code attributes, or -1 if these attributes are not code 266 * attributes. 267 * @param maxLocals 268 * the maximum number of local variables of the method 269 * corresponding to these code attributes, or -1 if these 270 * attributes are not code attributes. 271 * @param out 272 * where the attributes must be written. 273 */ 274 final void put(final ClassWriter cw, final byte[] code, final int len, 275 final int maxStack, final int maxLocals, final ByteVector out) { 276 Attribute attr = this; 277 while (attr != null) { 278 ByteVector b = attr.write(cw, code, len, maxStack, maxLocals); 279 out.putShort(cw.newUTF8(attr.type)).putInt(b.length); 280 out.putByteArray(b.data, 0, b.length); 281 attr = attr.next; 282 } 283 } 284 } | 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the copyright holders nor the names of its 44 * contributors may be used to endorse or promote products derived from 45 * this software without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 51 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 57 * THE POSSIBILITY OF SUCH DAMAGE. 58 */ 59 package jdk.internal.org.objectweb.asm; 60 61 import java.util.Arrays; 62 63 /** 64 * A non standard class, field, method or code attribute. 65 * 66 * @author Eric Bruneton 67 * @author Eugene Kuleshov 68 */ 69 public class Attribute { 70 71 /** 72 * The type of this attribute. 73 */ 74 public final String type; 75 76 /** 77 * The raw value of this attribute, used only for unknown attributes. 78 */ 79 byte[] value; 80 81 /** 82 * The next attribute in this attribute list. May be <tt>null</tt>. 266 * the maximum stack size of the method corresponding to these 267 * code attributes, or -1 if these attributes are not code 268 * attributes. 269 * @param maxLocals 270 * the maximum number of local variables of the method 271 * corresponding to these code attributes, or -1 if these 272 * attributes are not code attributes. 273 * @param out 274 * where the attributes must be written. 275 */ 276 final void put(final ClassWriter cw, final byte[] code, final int len, 277 final int maxStack, final int maxLocals, final ByteVector out) { 278 Attribute attr = this; 279 while (attr != null) { 280 ByteVector b = attr.write(cw, code, len, maxStack, maxLocals); 281 out.putShort(cw.newUTF8(attr.type)).putInt(b.length); 282 out.putByteArray(b.data, 0, b.length); 283 attr = attr.next; 284 } 285 } 286 287 //The stuff below is temporary - once proper support for nestmate attribute has been added, it can be safely removed. 288 //see also changes in ClassReader.accept. 289 290 public static class NestMembers extends Attribute { 291 public NestMembers() { 292 super("NestMembers"); 293 } 294 295 byte[] bytes; 296 String[] classes; 297 298 @Override 299 protected Attribute read(ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) { 300 int offset = off; 301 NestMembers a = new NestMembers(); 302 int size = cr.readShort(off); 303 a.classes = new String[size]; 304 off += 2; 305 for (int i = 0; i < size ; i++) { 306 a.classes[i] = cr.readClass(off, buf); 307 off += 2; 308 } 309 a.bytes = Arrays.copyOfRange(cr.b, offset, offset + len); 310 return a; 311 } 312 313 @Override 314 protected ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) { 315 ByteVector v = new ByteVector(bytes.length); 316 v.putShort(classes.length); 317 for (String s : classes) { 318 v.putShort(cw.newClass(s)); 319 } 320 return v; 321 } 322 } 323 324 public static class NestHost extends Attribute { 325 326 byte[] bytes; 327 String clazz; 328 329 public NestHost() { 330 super("NestHost"); 331 } 332 333 @Override 334 protected Attribute read(ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) { 335 int offset = off; 336 NestHost a = new NestHost(); 337 a.clazz = cr.readClass(off, buf); 338 a.bytes = Arrays.copyOfRange(cr.b, offset, offset + len); 339 return a; 340 } 341 342 @Override 343 protected ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) { 344 ByteVector v = new ByteVector(bytes.length); 345 v.putShort(cw.newClass(clazz)); 346 return v; 347 } 348 } 349 350 static final Attribute[] DEFAULT_ATTRIBUTE_PROTOS = new Attribute[] { 351 new NestMembers(), 352 new NestHost() 353 }; 354 } |