Android Open Source - objenesis J Rockit Legacy Instantiator






From Project

Back to project page objenesis.

License

The source code is released under:

Apache License

If you think the Android project objenesis listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * COPYRIGHT & LICENSE/*from  ww w  .  java  2s  .  c  o  m*/
 *
 * This code is Copyright (c) 2006 BEA Systems, inc. It is provided free, as-is and without any warranties for the purpose of
 * inclusion in Objenesis or any other open source project with a FSF approved license, as long as this notice is not
 * removed. There are no limitations on modifying or repackaging the code apart from this. 
 *
 * BEA does not guarantee that the code works, and provides no support for it. Use at your own risk.
 *
 * Originally developed by Leonardo Mesquita. Copyright notice added by Henrik Sthl, BEA JRockit Product Manager.
 *  
 */

package org.objenesis.instantiator.jrockit;

import java.lang.reflect.Method;

import org.objenesis.ObjenesisException;
import org.objenesis.instantiator.ObjectInstantiator;

/**
 * Instantiates a class by making a call to internal JRockit private methods. It is only supposed to
 * work on JRockit 1.4.2 JVMs prior to release R25.1. From release R25.1 on, JRockit supports
 * sun.reflect.ReflectionFactory, making this "trick" unnecessary. This instantiator will not call
 * any constructors.
 * 
 * @author Leonardo Mesquita
 * @see org.objenesis.instantiator.ObjectInstantiator
 * @see org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator
 */
public class JRockitLegacyInstantiator<T> implements ObjectInstantiator<T> {
   private static Method safeAllocObjectMethod = null;

   private static void initialize() {
      if(safeAllocObjectMethod == null) {
         Class<?> memSystem;
         try {
            memSystem = Class.forName("jrockit.vm.MemSystem");
            safeAllocObjectMethod = memSystem.getDeclaredMethod("safeAllocObject",
               new Class[] {Class.class});
            safeAllocObjectMethod.setAccessible(true);
         }
         catch(RuntimeException e) {
            throw new ObjenesisException(e);
         }
         catch(ClassNotFoundException e) {
            throw new ObjenesisException(e);
         }
         catch(NoSuchMethodException e) {
            throw new ObjenesisException(e);
         }
      }
   }

   private final Class<T> type;

   public JRockitLegacyInstantiator(Class<T> type) {
      initialize();
      this.type = type;
   }

   public T newInstance() {      
      try {
         return type.cast(safeAllocObjectMethod.invoke(null, type));
      }
      catch(Exception e) {
         throw new ObjenesisException(e);
      }
   }
}




Java Source Code List

org.objenesis.ObjenesisBase.java
org.objenesis.ObjenesisException.java
org.objenesis.ObjenesisHelper.java
org.objenesis.ObjenesisSerializer.java
org.objenesis.ObjenesisStd.java
org.objenesis.Objenesis.java
org.objenesis.benchmark.ConcurrentGetInstantiator.java
org.objenesis.benchmark.CreateObject.java
org.objenesis.instantiator.ObjectInstantiator.java
org.objenesis.instantiator.SerializationInstantiatorHelper.java
org.objenesis.instantiator.android.Android10Instantiator.java
org.objenesis.instantiator.android.Android17Instantiator.java
org.objenesis.instantiator.android.Android18Instantiator.java
org.objenesis.instantiator.android.AndroidSerializationInstantiator.java
org.objenesis.instantiator.basic.AccessibleInstantiator.java
org.objenesis.instantiator.basic.ConstructorInstantiator.java
org.objenesis.instantiator.basic.FailingInstantiator.java
org.objenesis.instantiator.basic.NewInstanceInstantiator.java
org.objenesis.instantiator.basic.NullInstantiator.java
org.objenesis.instantiator.basic.ObjectInputStreamInstantiator.java
org.objenesis.instantiator.basic.ObjectStreamClassInstantiator.java
org.objenesis.instantiator.gcj.GCJInstantiatorBase.java
org.objenesis.instantiator.gcj.GCJInstantiator.java
org.objenesis.instantiator.gcj.GCJSerializationInstantiator.java
org.objenesis.instantiator.jrockit.JRockitLegacyInstantiator.java
org.objenesis.instantiator.perc.PercInstantiator.java
org.objenesis.instantiator.perc.PercSerializationInstantiator.java
org.objenesis.instantiator.sun.SunReflectionFactoryHelper.java
org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.java
org.objenesis.instantiator.sun.SunReflectionFactorySerializationInstantiator.java
org.objenesis.instantiator.sun.UnsafeFactoryInstantiator.java
org.objenesis.strategy.BaseInstantiatorStrategy.java
org.objenesis.strategy.InstantiatorStrategy.java
org.objenesis.strategy.PlatformDescription.java
org.objenesis.strategy.SerializingInstantiatorStrategy.java
org.objenesis.strategy.SingleInstantiatorStrategy.java
org.objenesis.strategy.StdInstantiatorStrategy.java
org.objenesis.tck.CandidateLoader.java
org.objenesis.tck.Main.java
org.objenesis.tck.Reporter.java
org.objenesis.tck.TCK.java
org.objenesis.tck.TextReporter.java
org.objenesis.tck.android.ObjenesisTest.java
org.objenesis.tck.android.TckInstrumentation.java
org.objenesis.tck.candidates.ConstructorThrowingException.java
org.objenesis.tck.candidates.ConstructorWithArguments.java
org.objenesis.tck.candidates.ConstructorWithMandatoryArguments.java
org.objenesis.tck.candidates.DefaultPackageConstructor.java
org.objenesis.tck.candidates.DefaultPrivateConstructor.java
org.objenesis.tck.candidates.DefaultProtectedConstructor.java
org.objenesis.tck.candidates.DefaultPublicConstructor.java
org.objenesis.tck.candidates.NoConstructor.java
org.objenesis.tck.candidates.SerializableConstructorThrowingException.java
org.objenesis.tck.candidates.SerializableConstructorWithArguments.java
org.objenesis.tck.candidates.SerializableConstructorWithMandatoryArguments.java
org.objenesis.tck.candidates.SerializableDefaultPackageConstructor.java
org.objenesis.tck.candidates.SerializableDefaultPrivateConstructor.java
org.objenesis.tck.candidates.SerializableDefaultProtectedConstructor.java
org.objenesis.tck.candidates.SerializableDefaultPublicConstructor.java
org.objenesis.tck.candidates.SerializableNoConstructor.java
org.objenesis.tck.candidates.SerializableReplacer.java
org.objenesis.tck.candidates.SerializableResolver.java
org.objenesis.tck.candidates.SerializableWithAncestorThrowingException.java