Package com.esotericsoftware.reflectasm

Examples of com.esotericsoftware.reflectasm.FieldAccess


  }

  public void copy (Object original, Object copy) {
    try {
      if (accessIndex != -1) {
        FieldAccess access = (FieldAccess)fieldSerializer.access;
        access.set(copy, accessIndex, kryo.copy(access.get(original, accessIndex)));
      } else
        setField(copy, kryo.copy(getField(original)));
    } catch (IllegalAccessException ex) {
      throw new KryoException("Error accessing field: " + this + " (" + type.getName() + ")", ex);
    } catch (KryoException ex) {
View Full Code Here


public class FieldAccessBenchmark extends Benchmark {
  public FieldAccessBenchmark () throws Exception {
    int count = 1000000;
    Object[] dontCompileMeAway = new Object[count];

    FieldAccess access = FieldAccess.get(SomeClass.class);
    SomeClass someObject = new SomeClass();
    int index = access.getIndex("name");

    Field field = SomeClass.class.getField("name");

    for (int i = 0; i < 100; i++) {
      for (int ii = 0; ii < count; ii++) {
        access.set(someObject, index, "first");
        dontCompileMeAway[ii] = access.get(someObject, index);
      }
      for (int ii = 0; ii < count; ii++) {
        field.set(someObject, "first");
        dontCompileMeAway[ii] = field.get(someObject);
      }
    }
    warmup = false;

    for (int i = 0; i < 100; i++) {
      start();
      for (int ii = 0; ii < count; ii++) {
        access.set(someObject, index, "first");
        dontCompileMeAway[ii] = access.get(someObject, index);
      }
      end("FieldAccess");
    }
    for (int i = 0; i < 100; i++) {
      start();
View Full Code Here

    }

    public void copy (Object original, Object copy) {
      try {
        if (accessIndex != -1) {
          FieldAccess access = (FieldAccess)FieldSerializer.this.access;
          access.set(copy, accessIndex, access.get(original, accessIndex));
        } else
          field.set(copy, field.get(original));
      } catch (IllegalAccessException ex) {
        throw new KryoException("Error accessing field: " + this + " (" + type.getName() + ")", ex);
      } catch (KryoException ex) {
View Full Code Here

public class FieldAccessBenchmark extends Benchmark {
  public FieldAccessBenchmark () throws Exception {
    int count = 1000000;
    Object[] dontCompileMeAway = new Object[count];

    FieldAccess access = FieldAccess.get(SomeClass.class);
    SomeClass someObject = new SomeClass();
    int index = access.getIndex("name");

    Field field = SomeClass.class.getField("name");

    for (int i = 0; i < 100; i++) {
      for (int ii = 0; ii < count; ii++) {
        access.set(someObject, index, "first");
        dontCompileMeAway[ii] = access.get(someObject, index);
      }
      for (int ii = 0; ii < count; ii++) {
        field.set(someObject, "first");
        dontCompileMeAway[ii] = field.get(someObject);
      }
    }
    warmup = false;

    for (int i = 0; i < 100; i++) {
      start();
      for (int ii = 0; ii < count; ii++) {
        access.set(someObject, index, "first");
        dontCompileMeAway[ii] = access.get(someObject, index);
      }
      end("FieldAccess");
    }
    for (int i = 0; i < 100; i++) {
      start();
View Full Code Here

    }

    public void copy (Object original, Object copy) {
      try {
        if (accessIndex != -1) {
          FieldAccess access = (FieldAccess)FieldSerializer.this.access;
          access.set(copy, accessIndex, kryo.copy(access.get(original, accessIndex)));
        } else
          field.set(copy, kryo.copy(field.get(original)));
      } catch (IllegalAccessException ex) {
        throw new KryoException("Error accessing field: " + this + " (" + type.getName() + ")", ex);
      } catch (KryoException ex) {
View Full Code Here

     * @param fieldName 需要设置的值的属性
     * @param value 指定属性的值
     * @throws RuntimeException 如果对这个类使用反射失败或者指定的对象里面没有该属性
     */
    public static final void setFieldValue(Object host, String fieldName, boolean value) {
      FieldAccess access = FieldAccess.get(host.getClass());
      access.setBoolean(host, access.getIndex(fieldName), value);
    }
View Full Code Here

     * @param fieldName 需要设置的值的属性
     * @param value 指定属性的值
     * @throws RuntimeException 如果对这个类使用反射失败或者指定的对象里面没有该属性
     */
    public static final void setFieldValue(Object host, String fieldName, byte value) {
      FieldAccess access = FieldAccess.get(host.getClass());
      access.setByte(host, access.getIndex(fieldName), value);
    }
View Full Code Here

     * @param fieldName 需要设置的值的属性
     * @param value 指定属性的值
     * @throws RuntimeException 如果对这个类使用反射失败或者指定的对象里面没有该属性
     */
    public static final void setFieldValue(Object host, String fieldName, char value) {
      FieldAccess access = FieldAccess.get(host.getClass());
      access.setChar(host, access.getIndex(fieldName), value);
    }
View Full Code Here

     * @param fieldName 需要设置的值的属性
     * @param value 指定属性的值
     * @throws RuntimeException 如果对这个类使用反射失败或者指定的对象里面没有该属性
     */
    public static final void setFieldValue(Object host, String fieldName, double value) {
      FieldAccess access = FieldAccess.get(host.getClass());
      access.setDouble(host, access.getIndex(fieldName), value);
    }
View Full Code Here

     * @param fieldName 需要设置的值的属性
     * @param value 指定属性的值
     * @throws RuntimeException 如果对这个类使用反射失败或者指定的对象里面没有该属性
     */
    public static final void setFieldValue(Object host, String fieldName, float value) {
      FieldAccess access = FieldAccess.get(host.getClass());
      access.setFloat(host, access.getIndex(fieldName), value);
    }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.reflectasm.FieldAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.