< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.common/src/org/graalvm/compiler/core/common/FieldsScanner.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.core.common;
  26 
  27 import static org.graalvm.compiler.core.common.UnsafeAccess.UNSAFE;
  28 
  29 import java.lang.reflect.Field;
  30 import java.lang.reflect.Modifier;
  31 import java.util.ArrayList;
  32 
  33 import sun.misc.Unsafe;
  34 
  35 /**
  36  * Scans the fields in a class hierarchy.
  37  */
  38 public class FieldsScanner {
  39 
  40     /**
  41      * Determines the offset (in bytes) of a field.
  42      */
  43     public interface CalcOffset {
  44 
  45         long getOffset(Field field);
  46     }
  47 
  48     /**
  49      * Determines the offset (in bytes) of a field using {@link Unsafe#objectFieldOffset(Field)}.
  50      */
  51     public static class DefaultCalcOffset implements CalcOffset {


  52 
  53         @Override
  54         public long getOffset(Field field) {
  55             return UNSAFE.objectFieldOffset(field);
  56         }
  57     }
  58 
  59     /**
  60      * Describes a field in a class during {@linkplain FieldsScanner scanning}.
  61      */
  62     public static class FieldInfo implements Comparable<FieldInfo> {
  63         public final long offset;
  64         public final String name;
  65         public final Class<?> type;
  66         public final Class<?> declaringClass;
  67 
  68         public FieldInfo(long offset, String name, Class<?> type, Class<?> declaringClass) {
  69             this.offset = offset;
  70             this.name = name;
  71             this.type = type;




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.core.common;
  26 
  27 import static org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.getUnsafe;
  28 
  29 import java.lang.reflect.Field;
  30 import java.lang.reflect.Modifier;
  31 import java.util.ArrayList;
  32 
  33 import sun.misc.Unsafe;
  34 
  35 /**
  36  * Scans the fields in a class hierarchy.
  37  */
  38 public class FieldsScanner {
  39 
  40     /**
  41      * Determines the offset (in bytes) of a field.
  42      */
  43     public interface CalcOffset {
  44 
  45         long getOffset(Field field);
  46     }
  47 
  48     /**
  49      * Determines the offset (in bytes) of a field using {@link Unsafe#objectFieldOffset(Field)}.
  50      */
  51     public static class DefaultCalcOffset implements CalcOffset {
  52 
  53         private static final Unsafe UNSAFE = getUnsafe();
  54 
  55         @Override
  56         public long getOffset(Field field) {
  57             return UNSAFE.objectFieldOffset(field);
  58         }
  59     }
  60 
  61     /**
  62      * Describes a field in a class during {@linkplain FieldsScanner scanning}.
  63      */
  64     public static class FieldInfo implements Comparable<FieldInfo> {
  65         public final long offset;
  66         public final String name;
  67         public final Class<?> type;
  68         public final Class<?> declaringClass;
  69 
  70         public FieldInfo(long offset, String name, Class<?> type, Class<?> declaringClass) {
  71             this.offset = offset;
  72             this.name = name;
  73             this.type = type;


< prev index next >