package org.deuce.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import org.deuce.transform.Exclude;
import org.deuce.transform.asm.method.StaticMethodTransformer;

@Exclude
public class AddressUtil {

	/**
	 * Fetches the field direct address.
	 * @param field field reference
	 * @return direct address
	 */
	public static long getAddress( Field field) {
		if( Modifier.isStatic(field.getModifiers())){
			return UnsafeHolder.getUnsafe().staticFieldOffset(field);
		}else{
			return UnsafeHolder.getUnsafe().objectFieldOffset(field);
		}
	}
	
	/**
	 * Fetches base class handle
	 * @param clazz Class reference
	 * @return direct address
	 */
	public static Object staticFieldBase( Class clazz, String fieldName) {
		Field field;
		try {
			field = clazz.getDeclaredField(fieldName);
			return UnsafeHolder.getUnsafe().staticFieldBase( field);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} 
	}
	
	/**
	 * Fetches the array base offset
	 * @param arrClass array class
	 * @return offset
	 */
	public static int arrayBaseOffset( Class arrClass) {
		return UnsafeHolder.getUnsafe().arrayBaseOffset( arrClass);
	}
	
	/**
	 * Fetches the array index scale
	 * @param arrClass array class
	 * @return scale
	 */
	public static int arrayIndexScale( Class arrClass) {
		return UnsafeHolder.getUnsafe().arrayIndexScale( arrClass);
	}
}

@@ -787,16 +787,23 @@
 ld field
+ = null
 ;%0D%0A%09%09try
@@ -971,16 +971,37 @@
 ception(
+clazz + %22 %22 + field, 
 e);%0D%0A%09%09%7D

Add more details to Exception