comparison agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java @ 8031:927a311d00f9

8007320: NPG: move method annotations Summary: allocate method annotations and attach to ConstMethod if present Reviewed-by: dcubed, jiangli, sspitsyn, iklam
author coleenp
date Mon, 11 Feb 2013 14:06:22 -0500
parents fd74228fd5ca
children d2db09f281ca
comparison
equal deleted inserted replaced
8030:f989aff6946f 8031:927a311d00f9
1 /* 1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
47 private static int HAS_LINENUMBER_TABLE; 47 private static int HAS_LINENUMBER_TABLE;
48 private static int HAS_CHECKED_EXCEPTIONS; 48 private static int HAS_CHECKED_EXCEPTIONS;
49 private static int HAS_LOCALVARIABLE_TABLE; 49 private static int HAS_LOCALVARIABLE_TABLE;
50 private static int HAS_EXCEPTION_TABLE; 50 private static int HAS_EXCEPTION_TABLE;
51 private static int HAS_GENERIC_SIGNATURE; 51 private static int HAS_GENERIC_SIGNATURE;
52 private static int HAS_METHOD_ANNOTATIONS;
53 private static int HAS_PARAMETER_ANNOTATIONS;
54 private static int HAS_DEFAULT_ANNOTATIONS;
55 private static int HAS_TYPE_ANNOTATIONS;
56
57 private static final int sizeofShort = 2;
52 58
53 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 59 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
54 Type type = db.lookupType("ConstMethod"); 60 Type type = db.lookupType("ConstMethod");
55 constants = new MetadataField(type.getAddressField("_constants"), 0); 61 constants = new MetadataField(type.getAddressField("_constants"), 0);
56 constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0); 62 constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0);
57 flags = new ByteField(type.getJByteField("_flags"), 0); 63 flags = new CIntField(type.getCIntegerField("_flags"), 0);
58 64
59 // enum constants for flags 65 // enum constants for flags
60 HAS_LINENUMBER_TABLE = db.lookupIntConstant("ConstMethod::_has_linenumber_table").intValue(); 66 HAS_LINENUMBER_TABLE = db.lookupIntConstant("ConstMethod::_has_linenumber_table").intValue();
61 HAS_CHECKED_EXCEPTIONS = db.lookupIntConstant("ConstMethod::_has_checked_exceptions").intValue(); 67 HAS_CHECKED_EXCEPTIONS = db.lookupIntConstant("ConstMethod::_has_checked_exceptions").intValue();
62 HAS_LOCALVARIABLE_TABLE = db.lookupIntConstant("ConstMethod::_has_localvariable_table").intValue(); 68 HAS_LOCALVARIABLE_TABLE = db.lookupIntConstant("ConstMethod::_has_localvariable_table").intValue();
63 HAS_EXCEPTION_TABLE = db.lookupIntConstant("ConstMethod::_has_exception_table").intValue(); 69 HAS_EXCEPTION_TABLE = db.lookupIntConstant("ConstMethod::_has_exception_table").intValue();
64 HAS_GENERIC_SIGNATURE = db.lookupIntConstant("ConstMethod::_has_generic_signature").intValue(); 70 HAS_GENERIC_SIGNATURE = db.lookupIntConstant("ConstMethod::_has_generic_signature").intValue();
71 HAS_METHOD_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_method_annotations").intValue();
72 HAS_PARAMETER_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_parameter_annotations").intValue();
73 HAS_DEFAULT_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_default_annotations").intValue();
74 HAS_TYPE_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_type_annotations").intValue();
65 75
66 // Size of Java bytecodes allocated immediately after ConstMethod*. 76 // Size of Java bytecodes allocated immediately after ConstMethod*.
67 codeSize = new CIntField(type.getCIntegerField("_code_size"), 0); 77 codeSize = new CIntField(type.getCIntegerField("_code_size"), 0);
68 nameIndex = new CIntField(type.getCIntegerField("_name_index"), 0); 78 nameIndex = new CIntField(type.getCIntegerField("_name_index"), 0);
69 signatureIndex = new CIntField(type.getCIntegerField("_signature_index"), 0); 79 signatureIndex = new CIntField(type.getCIntegerField("_signature_index"), 0);
90 } 100 }
91 101
92 // Fields 102 // Fields
93 private static MetadataField constants; 103 private static MetadataField constants;
94 private static CIntField constMethodSize; 104 private static CIntField constMethodSize;
95 private static ByteField flags; 105 private static CIntField flags;
96 private static CIntField codeSize; 106 private static CIntField codeSize;
97 private static CIntField nameIndex; 107 private static CIntField nameIndex;
98 private static CIntField signatureIndex; 108 private static CIntField signatureIndex;
99 private static CIntField idnum; 109 private static CIntField idnum;
100 private static CIntField maxStack; 110 private static CIntField maxStack;
121 131
122 public long getConstMethodSize() { 132 public long getConstMethodSize() {
123 return constMethodSize.getValue(this); 133 return constMethodSize.getValue(this);
124 } 134 }
125 135
126 public byte getFlags() { 136 public long getFlags() {
127 return flags.getValue(this); 137 return flags.getValue(this);
128 } 138 }
129 139
130 public long getCodeSize() { 140 public long getCodeSize() {
131 return codeSize.getValue(this); 141 return codeSize.getValue(this);
251 } 261 }
252 262
253 public void iterateFields(MetadataVisitor visitor) { 263 public void iterateFields(MetadataVisitor visitor) {
254 visitor.doMetadata(constants, true); 264 visitor.doMetadata(constants, true);
255 visitor.doCInt(constMethodSize, true); 265 visitor.doCInt(constMethodSize, true);
256 visitor.doByte(flags, true); 266 visitor.doCInt(flags, true);
257 visitor.doCInt(codeSize, true); 267 visitor.doCInt(codeSize, true);
258 visitor.doCInt(nameIndex, true); 268 visitor.doCInt(nameIndex, true);
259 visitor.doCInt(signatureIndex, true); 269 visitor.doCInt(signatureIndex, true);
260 visitor.doCInt(codeSize, true); 270 visitor.doCInt(codeSize, true);
261 visitor.doCInt(maxStack, true); 271 visitor.doCInt(maxStack, true);
379 389
380 private boolean hasGenericSignature() { 390 private boolean hasGenericSignature() {
381 return (getFlags() & HAS_GENERIC_SIGNATURE) != 0; 391 return (getFlags() & HAS_GENERIC_SIGNATURE) != 0;
382 } 392 }
383 393
394 private boolean hasMethodAnnotations() {
395 return (getFlags() & HAS_METHOD_ANNOTATIONS) != 0;
396 }
397
398 private boolean hasParameterAnnotations() {
399 return (getFlags() & HAS_PARAMETER_ANNOTATIONS) != 0;
400 }
401
402 private boolean hasDefaultAnnotations() {
403 return (getFlags() & HAS_DEFAULT_ANNOTATIONS) != 0;
404 }
405
406 private boolean hasTypeAnnotations() {
407 return (getFlags() & HAS_TYPE_ANNOTATIONS) != 0;
408 }
409
384 410
385 //--------------------------------------------------------------------------- 411 //---------------------------------------------------------------------------
386 // Internals only below this point 412 // Internals only below this point
387 // 413 //
388 414
398 // Offset of start of compressed line number table (see method.hpp) 424 // Offset of start of compressed line number table (see method.hpp)
399 private long offsetOfCompressedLineNumberTable() { 425 private long offsetOfCompressedLineNumberTable() {
400 return offsetOfCodeEnd() + (isNative() ? 2 * VM.getVM().getAddressSize() : 0); 426 return offsetOfCodeEnd() + (isNative() ? 2 * VM.getVM().getAddressSize() : 0);
401 } 427 }
402 428
403 // Offset of last short in Method* 429 // Offset of last short in Method* before annotations, if present
404 private long offsetOfLastU2Element() { 430 private long offsetOfLastU2Element() {
405 return getSize() * VM.getVM().getObjectHeap().getOopSize() - 2; 431 int offset = 0;
432 if (hasMethodAnnotations()) offset++;
433 if (hasParameterAnnotations()) offset++;
434 if (hasTypeAnnotations()) offset++;
435 if (hasDefaultAnnotations()) offset++;
436 long wordSize = VM.getVM().getObjectHeap().getOopSize();
437 return (getSize() * wordSize) - (offset * wordSize) - sizeofShort;
406 } 438 }
407 439
408 // Offset of the generic signature index 440 // Offset of the generic signature index
409 private long offsetOfGenericSignatureIndex() { 441 private long offsetOfGenericSignatureIndex() {
410 return offsetOfLastU2Element(); 442 return offsetOfLastU2Element();
411 } 443 }
412 444
413 private long offsetOfCheckedExceptionsLength() { 445 private long offsetOfCheckedExceptionsLength() {
414 return hasGenericSignature() ? offsetOfLastU2Element() - 2 : 446 return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
415 offsetOfLastU2Element(); 447 offsetOfLastU2Element();
416 } 448 }
417 449
418 private int getCheckedExceptionsLength() { 450 private int getCheckedExceptionsLength() {
419 if (hasCheckedExceptions()) { 451 if (hasCheckedExceptions()) {
459 if (Assert.ASSERTS_ENABLED) { 491 if (Assert.ASSERTS_ENABLED) {
460 Assert.that(hasLocalVariableTable(), "should only be called if table is present"); 492 Assert.that(hasLocalVariableTable(), "should only be called if table is present");
461 } 493 }
462 494
463 if (hasExceptionTable()) { 495 if (hasExceptionTable()) {
464 return offsetOfExceptionTable() - 2; 496 return offsetOfExceptionTable() - sizeofShort;
465 } else if (hasCheckedExceptions()) { 497 } else if (hasCheckedExceptions()) {
466 return offsetOfCheckedExceptions() - 2; 498 return offsetOfCheckedExceptions() - sizeofShort;
467 } else { 499 } else {
468 return hasGenericSignature() ? offsetOfLastU2Element() - 2 : 500 return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
469 offsetOfLastU2Element(); 501 offsetOfLastU2Element();
470 } 502 }
471 } 503 }
472 504
473 private long offsetOfLocalVariableTable() { 505 private long offsetOfLocalVariableTable() {
491 private long offsetOfExceptionTableLength() { 523 private long offsetOfExceptionTableLength() {
492 if (Assert.ASSERTS_ENABLED) { 524 if (Assert.ASSERTS_ENABLED) {
493 Assert.that(hasExceptionTable(), "should only be called if table is present"); 525 Assert.that(hasExceptionTable(), "should only be called if table is present");
494 } 526 }
495 if (hasCheckedExceptions()) { 527 if (hasCheckedExceptions()) {
496 return offsetOfCheckedExceptions() - 2; 528 return offsetOfCheckedExceptions() - sizeofShort;
497 } else { 529 } else {
498 return hasGenericSignature() ? offsetOfLastU2Element() - 2 : 530 return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
499 offsetOfLastU2Element(); 531 offsetOfLastU2Element();
500 } 532 }
501 } 533 }
502 534
503 private long offsetOfExceptionTable() { 535 private long offsetOfExceptionTable() {