package jpower.core.internal;

import sun.misc.Unsafe;

import java.lang.instrument.Instrumentation;
import java.lang.reflect.Field;
import java.util.Vector;

public class PowerInternalSystem
{
   private static Instrumentation inst;

   public static void premain(String args, Instrumentation inst)
   {
      PowerInternalSystem.inst = inst;
   }

   @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"})
   public static Class[] getLoadedClasses(ClassLoader loader)
   {
      try
      {
         Field f = ClassLoader.class.getDeclaredField("classes");
         f.setAccessible(true);
         Vector<Class> classList = (Vector<Class>) f.get(loader);
         return classList.toArray(new Class[classList.size()]);
      }
      catch (NoSuchFieldException | IllegalAccessException e)
      {
         return null;
      }
   }

   public static Instrumentation getInstrumentation()
   {
      return inst;
   }

   public static Unsafe getUnsafe(Object object)
   {
      try
      {
         return (Unsafe) object.getClass().getDeclaredField("theUnsafe").get(object);
      }
      catch (Exception e)
      {
         return null;
      }
   }
}

@@ -24,16 +24,58 @@
 ernal;%0A%0A
+import jpower.core.reflect.FieldAccessor;%0A
 import s
@@ -90,16 +90,16 @@
 Unsafe;%0A
-
 %0Aimport 
@@ -140,40 +140,8 @@
 on;%0A
-import java.lang.reflect.Field;%0A
 impo
@@ -509,106 +509,8 @@
   %7B%0A
-         Field f = ClassLoader.class.getDeclaredField(%22classes%22);%0A         f.setAccessible(true);%0A
     
@@ -560,20 +560,47 @@
 s%3E) 
-f.get(loader
+new FieldAccessor(loader).get(%22classes%22
 );%0A 
@@ -908,18 +908,16 @@
  object)
-%0A 
   %7B%0A    
@@ -914,36 +914,33 @@
 t)  %7B%0A      
+ 
 try
-%0A     
  %7B%0A
+  
          ret
@@ -956,42 +956,37 @@
 fe) 
-object.getClass().getDeclaredField
+new FieldAccessor(object).get
 (%22th
@@ -998,28 +998,16 @@
 fe%22)
-.get(object)
 ;%0A      
 %7D%0A  
@@ -1002,31 +1002,26 @@
 ;%0A      
-%7D%0A    
  
+%7D
  catch (
 Exceptio
@@ -1012,37 +1012,33 @@
  catch (
-Exception e)%0A      %7B%0A
+Throwable e) %7B%0A  
         
@@ -1043,31 +1043,32 @@
    return null;%0A
+ 
       %7D%0A   %7D%0A%7D%0A

Make use of the FieldAccessor utility in the PowerInternalSystem class.