Instrumentation.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Instrumentation.java -- Implementation of this interface is used to
  2. instrument Java bytecode.
  3. Copyright (C) 2005 Free Software Foundation, Inc.
  4. This file is part of GNU Classpath.
  5. GNU Classpath is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU Classpath is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Classpath; see the file COPYING. If not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. Linking this library statically or dynamically with other modules is
  18. making a combined work based on this library. Thus, the terms and
  19. conditions of the GNU General Public License cover the whole
  20. combination.
  21. As a special exception, the copyright holders of this library give you
  22. permission to link this library with independent modules to produce an
  23. executable, regardless of the license terms of these independent
  24. modules, and to copy and distribute the resulting executable under
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. */
  32. package java.lang.instrument;
  33. /**
  34. * An Instrumentation object has transformers that will
  35. * be called each time a class is defined or redefined.
  36. * The object is given to a <code>premain</code> function
  37. * that is called before the <code>main</code> function.
  38. *
  39. * @author Nicolas Geoffray (nicolas.geoffray@menlina.com)
  40. * @since 1.5
  41. */
  42. public interface Instrumentation
  43. {
  44. /**
  45. * Adds a <code>ClassFileTransformer</class> object
  46. * to the instrumentation. Each time a class is defined
  47. * or redefined, the <code>transform</code> method of the
  48. * <code>transformer</code> object is called.
  49. *
  50. * @param transformer the transformer to add
  51. * @throws NullPointerException if transformer is null
  52. */
  53. void addTransformer(ClassFileTransformer transformer);
  54. /**
  55. * Removes the given transformer from the set of transformers
  56. * this Instrumentation object has.
  57. *
  58. * @param transformer the transformer to remove
  59. * @return true if the transformer was found and removed, false if
  60. * the transformer was not found
  61. * @throws NullPointerException if transformer is null
  62. */
  63. boolean removeTransformer(ClassFileTransformer transformer);
  64. /**
  65. * Returns if the current JVM supports class redefinition
  66. *
  67. * @return true if the current JVM supports class redefinition
  68. */
  69. boolean isRedefineClassesSupported();
  70. /**
  71. * Redefine classes present in the definitions array, with
  72. * the corresponding class files.
  73. *
  74. * @param definitions an array of classes to redefine
  75. *
  76. * @throws ClassNotFoundException if a class cannot be found
  77. * @throws UnmodifiableClassException if a class cannot be modified
  78. * @throws UnsupportedOperationException if the JVM does not support
  79. * redefinition or the redefinition made unsupported changes
  80. * @throws ClassFormatError if a class file is not valid
  81. * @throws NoClassDefFoundError if a class name is not equal to the name
  82. * in the class file specified
  83. * @throws UnsupportedClassVersionError if the class file version numbers
  84. * are unsupported
  85. * @throws ClassCircularityError if circularity occured with the new
  86. * classes
  87. * @throws LinkageError if a linkage error occurs
  88. * @throws NullPointerException if the definitions array is null, or any
  89. * of its element
  90. *
  91. * @see #isRedefineClassesSupported()
  92. * @see #addTransformer(java.lang.instrument.ClassFileTransformer)
  93. * @see ClassFileTransformer
  94. */
  95. void redefineClasses(ClassDefinition[] definitions)
  96. throws ClassNotFoundException,
  97. UnmodifiableClassException;
  98. /**
  99. * Get all the classes loaded by the JVM.
  100. *
  101. * @return an array containing all the classes loaded by the JVM. The array
  102. * is empty if no class is loaded.
  103. */
  104. Class[] getAllLoadedClasses();
  105. /**
  106. * Get all the classes loaded by a given class loader
  107. *
  108. * @param loader the loader
  109. *
  110. * @return an array containing all the classes loaded by the given loader.
  111. * The array is empty if no class was loaded by the loader.
  112. */
  113. Class[] getInitiatedClasses(ClassLoader loader);
  114. /**
  115. * Get the size of an object. It contains the size of all fields.
  116. *
  117. * @param objectToSize the object
  118. * @return the size of the object
  119. * @throws NullPointerException if objectToSize is null.
  120. */
  121. long getObjectSize(Object objectToSize);
  122. }