High performance Java reflection

Overview

Build Status Maven Central

Please use the ReflectASM discussion group for support.

Overview

ReflectASM is a very small Java library that provides high performance reflection by using code generation. An access class is generated to set/get fields, call methods, or create a new instance. The access class uses bytecode rather than Java's reflection, so it is much faster. It can also access primitive fields via bytecode to avoid boxing.

Performance

The source code for these benchmarks is included in the project. The above charts were generated on Oracle's Java 7u3, server VM.

Installation

To use reflectasm with maven, please use the following snippet in your pom.xml

    <dependency>
        <groupId>com.esotericsoftware</groupId>
        <artifactId>reflectasm</artifactId>
        <version>1.11.9</version>
    </dependency>

Usage

Method reflection with ReflectASM:

SomeClass someObject = ...
MethodAccess access = MethodAccess.get(SomeClass.class);
access.invoke(someObject, "setName", "Awesome McLovin");
String name = (String)access.invoke(someObject, "getName");

Field reflection with ReflectASM:

SomeClass someObject = ...
FieldAccess access = FieldAccess.get(SomeClass.class);
access.set(someObject, "name", "Awesome McLovin");
String name = (String)access.get(someObject, "name");

Constructor reflection with ReflectASM:

ConstructorAccess<SomeClass> access = ConstructorAccess.get(SomeClass.class);
SomeClass someObject = access.newInstance();

Avoiding Name Lookup

For maximum performance when methods or fields are accessed repeatedly, the method or field index should be used instead of the name:

SomeClass someObject = ...
MethodAccess access = MethodAccess.get(SomeClass.class);
int addNameIndex = access.getIndex("addName");
for (String name : names)
    access.invoke(someObject, addNameIndex, "Awesome McLovin");

Iterate all fields:

FieldAccess access = FieldAccess.get(SomeClass.class);
for(int i = 0, n = access.getFieldCount(); i < n; i++) {
    access.set(instanceObject, i, valueToPut);              
}

Visibility

ReflectASM can always access public members. An attempt is made to define access classes in the same classloader (using setAccessible) and package as the accessed class. If the security manager allows setAccessible to succeed, then protected and default access (package private) members can be accessed. If setAccessible fails, no exception is thrown, but only public members can be accessed. Private members can never be accessed.

Exceptions

Stack traces when using ReflectASM are a bit cleaner. Here is Java's reflection calling a method that throws a RuntimeException:

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.example.SomeCallingCode.doit(SomeCallingCode.java:22)
Caused by: java.lang.RuntimeException
	at com.example.SomeClass.someMethod(SomeClass.java:48)
	... 5 more

Here is the same but when ReflectASM is used:

Exception in thread "main" java.lang.RuntimeException
	at com.example.SomeClass.someMethod(SomeClass.java:48)
	at com.example.SomeClassMethodAccess.invoke(Unknown Source)
	at com.example.SomeCallingCode.doit(SomeCallingCode.java:22)

If ReflectASM is used to invoke code that throws a checked exception, the checked exception is thrown. Because it is a compilation error to use try/catch with a checked exception around code that doesn't declare that exception as being thrown, you must catch Exception if you care about catching a checked exception in code you invoke with ReflectASM.

Comments
  • Repackage asm

    Repackage asm

    This library use asm 5.1 (at the moment) direclty. However as per http://asm.ow2.org/doc/faq.html#Q15, it suggest that

    Tools and frameworks that are using ASM for bytecode processing (e.g. Hibernate, CGLIB, AspectWerkz) should repackage ASM code within their own name space. This can be automated with Jar Jar Links tool.

    Here is a real issue caused by ASM library version conflict between sun's jersey and ReflectASM

    opened by greenlaw110 17
  • my contribution

    my contribution

    http://pastebin.com/yvu5zVJZ

    /******************************************************************************
     * Inspired by https://github.com/EsotericSoftware/reflectasm
     * the main idea is to take away introspection from ReflectASM
     *
     * You must obtain reflection member (Constructor,Method or Field)
     * yourself then pass it to FastReflection.of() method to obtain
     * code generated access-object...
     *
     * Also (since it operate per-member basis) it takes away ugly switches
     * into generated bytecode, supports parametrized constructors and
     * static fields/members...
     */
    
    opened by dimzon 11
  • Boost bytecode FieldAccess generation by hand-calculating MAXS

    Boost bytecode FieldAccess generation by hand-calculating MAXS

    From [email protected] on June 13, 2012 15:51:05

    I added this comment to a closed issue, by I clone it here as a new Improvement suggestion:

    Instead of letting ClassWriter to autocompute MAXS, these are the right ones:

    ClassWriter cw = new ClassWriter(0); ... In the constructor: mv.visitMaxs(1, 1); In insertSetObjectBytecode: mv.visitMaxs(4, 4); In insertSetPrimitiveBytecode: mv.visitMaxs(4, 4); In insertGetStringBytecode: mv.visitMaxs(4, 3); In insertGetObjectBytecode: mv.visitMaxs(4, 3); In insertGetPrimitiveBytecode: mv.visitMaxs(4, 3);

    This gives a good boost to the start-up time for facades creation.

    The same is already done in ConstructorAccess (and we could do the argument-counting for the MethodAccess)...

    Regards, Jesús

    Original issue: http://code.google.com/p/reflectasm/issues/detail?id=9

    bug imported Priority-Medium 
    opened by ghost 10
  • ConstructAccess shoud support non-static inner classes instantiation

    ConstructAccess shoud support non-static inner classes instantiation

    From [email protected] on June 13, 2012 15:47:40

    Look at the attachment with my proposal for adding a "T newInstance (Object enclosingInstance)" method, allowing inner classes instantiation :-)

    So caller could do:

    if (constructorAccess.isNonStaticMemberClass()) {
        newInstance = constructorAccess.newInstance(enclosingInstance);
    }
    else {
        newInstance = constructorAccess.newInstance();
    }
    

    Regards!

    Attachment: ConstructorAccess.java

    Original issue: http://code.google.com/p/reflectasm/issues/detail?id=8

    bug imported Priority-Medium 
    opened by ghost 9
  • OSGi import org.objectweb.asm;version=

    OSGi import org.objectweb.asm;version="[5.1,6)"

    The library defines the "Import-Package: org.objectweb.asm;version="[5.1,6)"" MANIFEST.MF header even though the asm library is shaded and therefore no import is needed.

    opened by swimmesberger 6
  • Use ehcache to storage MethodAccess occured NotSerializableException

    Use ehcache to storage MethodAccess occured NotSerializableException

    EntityMethodAccess is created by ReflectASM,I think it should implements Seriablizable

    java.io.NotSerializableException: com.juno.java.frame.core.model.EntityMethodAccess at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:440) at net.sf.ehcache.Element.writeObject(Element.java:867) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97) at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:399) at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:381) at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:473) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1067) at net.sf.ehcache.store.disk.DiskStorageFactory$IndexWriteTask.call(DiskStorageFactory.java:1104) at net.sf.ehcache.store.disk.DiskStorageFactory.unbind(DiskStorageFactory.java:917) at net.sf.ehcache.store.disk.DiskStore.dispose(DiskStore.java:664) at net.sf.ehcache.store.CacheStore.dispose(CacheStore.java:327) at net.sf.ehcache.Cache.dispose(Cache.java:2521) at net.sf.ehcache.CacheManager.shutdown(CacheManager.java:1523) at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.destroy(EhCacheManagerFactoryBean.java:190) at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:262) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:972) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:979) at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1006) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:982) at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:901)

    opened by qianzhiheilv 5
  • request for primitive field gettor/settor methods

    request for primitive field gettor/settor methods

    From [email protected] on December 08, 2011 01:29:50

    Please provide any additional information below. I noticed that for field access every access gets promoted to Object by calling the valueOf methods on the primitive wrapper classes. So you have provided an alternative to Field#set(Object, Object) and Field#get(Object). Why don't you also provide primitive methods like setInt and getInt? If the caller knows they will always be dealing with a certain primitive field these read methods would not need to allocate any object but just return the bits of the primitive. Wouldn't this help kyro be even a bit faster?

    Original issue: http://code.google.com/p/reflectasm/issues/detail?id=4

    bug imported Priority-Medium 
    opened by ghost 5
  • Test failures with OpenJDK17: probably ClassLoader evolutions since OpenJDK11

    Test failures with OpenJDK17: probably ClassLoader evolutions since OpenJDK11

    Hello,

    I am maintaining reflectasm in Debian. We have recently switched from OpenJDK11 to OpenJDK17 and this caused failures in the tests in com.esotericsoftware.reflectasm.ConstructorAccessTest (output at the end of my report).

    I digged a bit, ran testHasProtectedConstructor and looked at loader1, loader2 and systemClassLoader in AccessClassLoader.areInSameRuntimeClassLoader called by ConstructorAccess.get. They are respectively jdk.internal.loader.ClassLoaders$AppClassLoader@46fbb2c1, com.esotericsoftware.reflectasm.AccessClassLoader@42d3bd8b , and jdk.internal.loader.ClassLoaders$AppClassLoader@46fbb2c1 when using OpenJDK17, whereas with OpenJDK11 they are respectively jdk.internal.loader.ClassLoaders$AppClassLoader@55054057, jdk.internal.loader.ClassLoaders$AppClassLoader@55054057, and jdk.internal.loader.ClassLoaders$AppClassLoader@55054057 when using OpenJDK11. Thus I suspect something has changed in the ClassLoader mechanism, perhaps you would like to investigate.

    Also, in AccessClassLoader.areInSameRuntimeClassLoader, I think you would like to use .equals() methods instead of == as, e.g. in if (type1.getPackage() == type2.getPackage()), you are willing to compare values and not references.

    Cheers,

    Pierre

    [INFO] Running com.esotericsoftware.reflectasm.ConstructorAccessTest Unexpected exception happened: java.lang.RuntimeException: Class cannot be created (the no-arg constructor is protected or package-protected, and its ConstructorAccess could not be defined in the same class loader): com.esotericsoftware.reflectasm.ConstructorAccessTest$HasProtectedConstructor Unexpected exception happened: java.lang.RuntimeException: Class cannot be created (the no-arg constructor is protected or package-protected, and its ConstructorAccess could not be defined in the same class loader): com.esotericsoftware.reflectasm.ConstructorAccessTest$HasPublicConstructor Expected exception happened: java.lang.RuntimeException: Class cannot be created (missing no-arg constructor): com.esotericsoftware.reflectasm.ConstructorAccessTest$HasArgumentConstructor Unexpected exception happened: java.lang.RuntimeException: Class cannot be created (the no-arg constructor is protected or package-protected, and its ConstructorAccess could not be defined in the same class loader): com.esotericsoftware.reflectasm.ConstructorAccessTest$HasPackageProtectedConstructor Expected exception happened: java.lang.RuntimeException: Class cannot be created (the no-arg constructor is private): com.esotericsoftware.reflectasm.ConstructorAccessTest$HasPrivateConstructor [ERROR] Tests run: 7, Failures: 3, Errors: 1, Skipped: 0, Time elapsed: 0.057 s <<< FAILURE! - in com.esotericsoftware.reflectasm.ConstructorAccessTest [ERROR] testHasProtectedConstructor(com.esotericsoftware.reflectasm.ConstructorAccessTest) Time elapsed: 0.029 s <<< FAILURE! junit.framework.AssertionFailedError at com.esotericsoftware.reflectasm.ConstructorAccessTest.testHasProtectedConstructor(ConstructorAccessTest.java:74)

    [ERROR] testHasPublicConstructor(com.esotericsoftware.reflectasm.ConstructorAccessTest) Time elapsed: 0.004 s <<< FAILURE! junit.framework.AssertionFailedError at com.esotericsoftware.reflectasm.ConstructorAccessTest.testHasPublicConstructor(ConstructorAccessTest.java:98)

    [ERROR] testPackagePrivateNewInstance(com.esotericsoftware.reflectasm.ConstructorAccessTest) Time elapsed: 0.002 s <<< ERROR! java.lang.RuntimeException: Class cannot be created (the no-arg constructor is protected or package-protected, and its ConstructorAccess could not be defined in the same class loader): com.esotericsoftware.reflectasm.ConstructorAccessTest$PackagePrivateClass at com.esotericsoftware.reflectasm.ConstructorAccessTest.testPackagePrivateNewInstance(ConstructorAccessTest.java:31)

    [ERROR] testHasPackageProtectedConstructor(com.esotericsoftware.reflectasm.ConstructorAccessTest) Time elapsed: 0.007 s <<< FAILURE! junit.framework.AssertionFailedError at com.esotericsoftware.reflectasm.ConstructorAccessTest.testHasPackageProtectedConstructor(ConstructorAccessTest.java:86)

    opened by pgrt 4
  • Revisit maven shading/release strategy

    Revisit maven shading/release strategy

    Currently reflectasm releases a JAR with a transitive dependency on ASM as

    <groupId>com.esotericsoftware</groupId>
    <artifactId>reflectasm</artifactId>
    <version>1.10.0</version>
    

    and a JAR with ASM bundled and relocated as

    <groupId>com.esotericsoftware</groupId>
    <artifactId>reflectasm</artifactId>
    <version>1.10.0</version>
    <classifier>shaded</classifier>
    

    This causes some minor headaches such as the shaded JAR sharing a POM with the original JAR so it still has a transitive dependency on ASM which needs to be excluded. But more importantly, using a classifier changes the maven coordinates. This makes it possible to have both the normal and shaded JAR end up in your dependency tree. It also makes it impossible to use Maven's dependencyManagement facility to control whether you want the normal or shaded JAR.

    I think it would be better to distinguish the shaded JAR with a version suffix, something like 1.10.0-shaded. By using the same maven coordinates, you're guaranteed that you only have either the normal or shaded JAR in your dependency tree, and it's easy to control which one you get through dependency management without needing to resort to exclusions and other hackery

    opened by jhaber 4
  • The access classes defined by AccessClassLoader don't have proper ProtectionDomain

    The access classes defined by AccessClassLoader don't have proper ProtectionDomain

    From [email protected] on March 25, 2013 11:04:11

    The access classes defined by AccessClassLoader don't have proper ProtectionDomain. It causes issue when the reflectasm is used in the environment with SecurityManger and customer security policy. The access will be denied when the operated class need to access restricted resource.

    The exception likes

    INFO | jvm 1 | 2013/03/22 05:09:09 | java.security.AccessControlException: access denied ("java.io.FilePermission":\bb_content\locale\en_US\plugins\cs_locales.properties" "read") INFO | jvm 1 | 2013/03/22 05:09:09 | at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366) INFO | jvm 1 | 2013/03/22 05:09:09 | at java.security.AccessController.checkPermission(AccessController.java:560) INFO | jvm 1 | 2013/03/22 05:09:09 | at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) INFO | jvm 1 | 2013/03/22 05:09:09 | at java.lang.SecurityManager.checkRead(SecurityManager.java:888) INFO | jvm 1 | 2013/03/22 05:09:09 | at java.io.File.exists(File.java:770) INFO | jvm 1 | 2013/03/22 05:09:09 | at blackboard.redis.TestPermission.run(TestPermission.java:11) INFO | jvm 1 | 2013/03/22 05:09:09 | at blackboard.redis.TestPermissionMethodAccess.invoke(Unknown Source) INFO | jvm 1 | 2013/03/22 05:09:09 | at com.esotericsoftware.reflectasm.MethodAccess.invoke(MethodAccess.java:25)

    I'm using the latest version 1.07. I think that would be great if the generated access classes have the same ProtectionDomain with reflectasm.

    Here is a patch based on 1.07.

    Index: AccessClassLoader.java

    --- AccessClassLoader.java (revision 49) +++ AccessClassLoader.java (working copy) @@ -2,6 +2,7 @@ package com.esotericsoftware.reflectasm; import java.lang.reflect.Method; +import java.security.ProtectionDomain; import java.util.ArrayList; class AccessClassLoader extends ClassLoader { @@ -37,9 +38,9 @@ try { // Attempt to load the access class in the same loader, which makes protected and default access members accessible. Method method = ClassLoader.class.getDeclaredMethod("defineClass", new Class[] {String.class, byte[].class, int.class,

    •           int.class});&#13;
      
    •           int.class, ProtectionDomain.class});&#13;
          method.setAccessible(true);&#13;
      
    •       return (Class)method.invoke(getParent(), new Object[] {name, bytes, Integer.valueOf(0), Integer.valueOf(bytes.length)});&#13;
      
    •       return (Class)method.invoke(getParent(), new Object[] {name, bytes, Integer.valueOf(0), Integer.valueOf(bytes.length), getClass().getProtectionDomain()});&#13;
      } catch (Exception ignored) {&#13;
      }&#13;
      return defineClass(name, bytes, 0, bytes.length);
      

    Original issue: http://code.google.com/p/reflectasm/issues/detail?id=14

    bug imported Priority-Medium 
    opened by ghost 4
  • Performance optimization: Try to load accessClass without synchronization

    Performance optimization: Try to load accessClass without synchronization

    In EsotericSoftware/kryo#422 it's reported that the sychronization in ConstructorAccess.get on the loader is causing significant thread contention.

    This change tries to prevent this, via double checked locking (just adding an unsynchronized accessClass = loader.loadClass(accessClassName);, the synchronized block is unchanged - unfortunately the diff doesn't show this clearly).

    Because it's the same pattern it's also done for FieldAccess and MethodAccess as well.

    opened by magro 3
  • Is it possible to invoke static method in interface

    Is it possible to invoke static method in interface

    Hi there, if had a interface as below: public interface SomeClass2 {

    	 public static String staticMethod (String a, int b) {
    		return "meow! " + a + ", " + b;
    	}
    }
    

    is it possible to use the library to invoke the static method?

    opened by louisypchan 0
  • Add support searching default methods since Java 8

    Add support searching default methods since Java 8

    When using MethodAccess.get(Class type), I found that it can't find the default methods in interface("type" is not interface but implements an interface which have many default methods in it).

    opened by AHGGG 0
  • Scala 3 lazy val implementation breaks FieldAccess reflection

    Scala 3 lazy val implementation breaks FieldAccess reflection

    Scala 3 changed the implementation of lazy vals. Classes containing a lazy val end up with a field called 0bitmap$1:

    Compiled from "Test.scala"
    public class Test implements scala.Product,java.io.Serializable {
      public static final long OFFSET$0;
      public long 0bitmap$1;
      private final byte a;
      ...
    

    This results in a ClassFormatError:

    Cause: java.lang.ClassFormatError: Illegal field name "0bitmap$1" in class io/altoo/akka/serialization/kryo/TestFieldAccess
    	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
    	at com.esotericsoftware.reflectasm.AccessClassLoader.defineClass(AccessClassLoader.java:78)
    	at com.esotericsoftware.reflectasm.AccessClassLoader.defineAccessClass(AccessClassLoader.java:57)
    	at com.esotericsoftware.reflectasm.FieldAccess.get(FieldAccess.java:173)
    

    (Report from https://github.com/EsotericSoftware/kryo/issues/882)

    opened by nvollmar 0
  • Bump junit from 4.8.2 to 4.13.1

    Bump junit from 4.8.2 to 4.13.1

    Bumps junit from 4.8.2 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    JUnit 4.12

    Please refer to the release notes for details.

    JUnit 4.12 Beta 3

    Please refer to the release notes for details.

    JUnit 4.12 Beta 2

    No release notes provided.

    JUnit 4.12 Beta 1

    No release notes provided.

    JUnit 4.11

    No release notes provided.

    Changelog

    Sourced from junit's changelog.

    Summary of changes in version 4.13.1

    Rules

    Security fix: TemporaryFolder now limits access to temporary folders on Java 1.7 or later

    A local information disclosure vulnerability in TemporaryFolder has been fixed. See the published security advisory for details.

    Test Runners

    [Pull request #1669:](junit-team/junit#1669) Make FrameworkField constructor public

    Prior to this change, custom runners could make FrameworkMethod instances, but not FrameworkField instances. This small change allows for both now, because FrameworkField's constructor has been promoted from package-private to public.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • support for multi-argument constructors

    support for multi-argument constructors

    add newInstance0() to support for multi-argument constructors usage:

    Constructor constructor = SomeClass.class.getConstructor(String.class);
    ConstructorAccess<SomeClass> access = ConstructorAccess.get(SomeClass.class, constructor);
    assertEquals(new SomeClass("coo), access.newInstance0("coo"));
    

    bytecode:

    public Object newInstance0(Object[] var1) {
        return new SomeClass((String)var1[0]);
    }
    

    Performance comparison of access.newInstance("coo") and constructor.newInstance("coo")

    opened by Mr14huashao 2
  • MethodAccess.invoke takes a lot physical memory

    MethodAccess.invoke takes a lot physical memory

    I find when the Class contains more than 150 fields, and use MethodAccess.invoke to run the method, it would take a lot of physical memory, those memory is outside the heap and it cannot be tracked in java NMT. This will cause the docker or k8s oom kill.

    Under jdk1.8.0_201, CentOS 7

    import lombok.Data;
    
    @Data
    public class TestDomain {
    
        private String field1;
        private String field2;
        private String field3;
        private String field4;
        private String field5;
        private String field6;
        private String field7;
        private String field8;
        private String field9;
        private String field10;
        private String field11;
        private String field12;
        private String field13;
        private String field14;
        private String field15;
        private String field16;
        private String field17;
        private String field18;
        private String field19;
        private String field20;
        private String field21;
        private String field22;
        private String field23;
        private String field24;
        private String field25;
        private String field26;
        private String field27;
        private String field28;
        private String field29;
        private String field30;
        private String field31;
        private String field32;
        private String field33;
        private String field34;
        private String field35;
        private String field36;
        private String field37;
        private String field38;
        private String field39;
        private String field40;
    
        private Long field41;
        private Long field42;
        private Long field43;
        private Long field44;
        private Long field45;
        private Long field46;
        private Long field47;
        private Long field48;
        private Long field49;
        private Long field50;
    
        private Double field51;
        private Double field52;
        private Double field53;
        private Double field54;
        private Double field55;
        private Double field56;
        private Double field57;
        private Double field58;
        private Double field59;
        private Double field60;
    
    
        private String field61;
        private String field62;
        private String field63;
        private String field64;
        private String field65;
        private String field66;
        private String field67;
        private String field68;
        private String field69;
        private String field70;
    
        private String field71;
        private String field72;
        private String field73;
        private String field74;
        private String field75;
        private String field76;
        private String field77;
        private String field78;
        private String field79;
        private String field80;
    
        private String field81;
        private String field82;
        private String field83;
        private String field84;
        private String field85;
        private String field86;
        private String field87;
        private String field88;
        private String field89;
        private String field90;
    
        private String field91;
        private String field92;
        private String field93;
        private String field94;
        private String field95;
        private String field96;
        private String field97;
        private String field98;
        private String field99;
        private String field100;
    
        private String field101;
        private String field102;
        private String field103;
        private String field104;
        private String field105;
        private String field106;
        private String field107;
        private String field108;
        private String field109;
        private String field110;
    
        private String field111;
        private String field112;
        private String field113;
        private String field114;
        private String field115;
        private String field116;
        private String field117;
        private String field118;
        private String field119;
        private String field120;
    
    
        private String field121;
        private String field122;
        private String field123;
        private String field124;
        private String field125;
        private String field126;
        private String field127;
        private String field128;
        private String field129;
        private String field130;
    
        private String field131;
        private String field132;
        private String field133;
        private String field134;
        private String field135;
        private String field136;
        private String field137;
        private String field138;
        private String field139;
        private String field140;
    
        private String field141;
        private String field142;
        private String field143;
        private String field144;
        private String field145;
        private String field146;
        private String field147;
        private String field148;
        private String field149;
        private String field150;
    
        private String field151;
        private String field152;
        private String field153;
        private String field154;
        private String field155;
        private String field156;
        private String field157;
        private String field158;
        private String field159;
        private String field160;
    
        private String field161;
        private String field162;
        private String field163;
        private String field164;
        private String field165;
        private String field166;
        private String field167;
        private String field168;
        private String field169;
        private String field170;
    
        private String field171;
        private String field172;
        private String field173;
        private String field174;
        private String field175;
        private String field176;
        private String field177;
        private String field178;
        private String field179;
        private String field180;
    
    }
    
    
    @RunWith(JUnit4.class)
    @Slf4j
    public class TestDomainMethodAccess {
        @Test
        public void test() throws Exception{
            OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
            MethodAccess methodAccess = ReflectionUtil.getMethodAccess(TestDomain.class);
    
            for (int i = 0; i < 1000; i++) {
                TestDomain source = new TestDomain();
                for (int j = 0; j < 180; j++) {
                    methodAccess.invoke(source, "getField" + (j + 1), new Object[0]);
                }
                Thread.sleep(100);
                System.out.println(""+ StringUtils.rightPad(""+(i+1),3)+"Call," +
                        "Free OS Mem "+StringUtils.leftPad(""+osmxb.getFreePhysicalMemorySize()/1024/1024,6)+"MB"+
                        ", JVM Mem "+StringUtils.leftPad(""+Runtime.getRuntime().totalMemory()/1024/1024,6)+"MB");
            }
        }
    }
    

    the result

    Connected to the target VM, address: '127.0.0.1:53946', transport: 'socket'
    1  Call,Free OS Mem   2114MB, JVM Mem    123MB
    2  Call,Free OS Mem   2113MB, JVM Mem    123MB
    3  Call,Free OS Mem   2101MB, JVM Mem    123MB
    4  Call,Free OS Mem   2082MB, JVM Mem    123MB
    5  Call,Free OS Mem   2081MB, JVM Mem    123MB
    6  Call,Free OS Mem   2081MB, JVM Mem    123MB
    7  Call,Free OS Mem   2081MB, JVM Mem    123MB
    8  Call,Free OS Mem   2081MB, JVM Mem    123MB
    9  Call,Free OS Mem   2081MB, JVM Mem    123MB
    10 Call,Free OS Mem   2081MB, JVM Mem    123MB
    11 Call,Free OS Mem   2081MB, JVM Mem    123MB
    12 Call,Free OS Mem   2080MB, JVM Mem    123MB
    13 Call,Free OS Mem   2080MB, JVM Mem    123MB
    14 Call,Free OS Mem   2108MB, JVM Mem    123MB
    15 Call,Free OS Mem   2108MB, JVM Mem    123MB
    16 Call,Free OS Mem   2108MB, JVM Mem    123MB
    17 Call,Free OS Mem   2108MB, JVM Mem    123MB
    18 Call,Free OS Mem   2108MB, JVM Mem    123MB
    19 Call,Free OS Mem   2108MB, JVM Mem    123MB
    20 Call,Free OS Mem   2108MB, JVM Mem    123MB
    21 Call,Free OS Mem   2121MB, JVM Mem    123MB
    22 Call,Free OS Mem   2121MB, JVM Mem    123MB
    23 Call,Free OS Mem   2121MB, JVM Mem    123MB
    24 Call,Free OS Mem   2121MB, JVM Mem    123MB
    25 Call,Free OS Mem   2121MB, JVM Mem    123MB
    26 Call,Free OS Mem   2121MB, JVM Mem    123MB
    27 Call,Free OS Mem   2121MB, JVM Mem    123MB
    28 Call,Free OS Mem   2121MB, JVM Mem    123MB
    29 Call,Free OS Mem   2121MB, JVM Mem    123MB
    30 Call,Free OS Mem   2121MB, JVM Mem    123MB
    31 Call,Free OS Mem   2121MB, JVM Mem    123MB
    32 Call,Free OS Mem   2111MB, JVM Mem    123MB
    33 Call,Free OS Mem   2112MB, JVM Mem    123MB
    34 Call,Free OS Mem   2112MB, JVM Mem    123MB
    35 Call,Free OS Mem   2112MB, JVM Mem    123MB
    36 Call,Free OS Mem   2112MB, JVM Mem    123MB
    37 Call,Free OS Mem   2112MB, JVM Mem    123MB
    38 Call,Free OS Mem   2112MB, JVM Mem    123MB
    39 Call,Free OS Mem   2112MB, JVM Mem    123MB
    40 Call,Free OS Mem   2112MB, JVM Mem    123MB
    41 Call,Free OS Mem   1845MB, JVM Mem    123MB
    42 Call,Free OS Mem   1821MB, JVM Mem    123MB
    43 Call,Free OS Mem   1788MB, JVM Mem    123MB
    44 Call,Free OS Mem   2010MB, JVM Mem    123MB
    45 Call,Free OS Mem   2010MB, JVM Mem    123MB
    46 Call,Free OS Mem   2010MB, JVM Mem    123MB
    47 Call,Free OS Mem   2010MB, JVM Mem    123MB
    48 Call,Free OS Mem   2010MB, JVM Mem    123MB
    49 Call,Free OS Mem   2010MB, JVM Mem    123MB
    50 Call,Free OS Mem   2010MB, JVM Mem    123MB
    51 Call,Free OS Mem   1509MB, JVM Mem    123MB
    52 Call,Free OS Mem   1420MB, JVM Mem    123MB
    53 Call,Free OS Mem   1318MB, JVM Mem    123MB
    54 Call,Free OS Mem   1221MB, JVM Mem    123MB
    55 Call,Free OS Mem   1124MB, JVM Mem    123MB
    56 Call,Free OS Mem   1026MB, JVM Mem    123MB
    57 Call,Free OS Mem   1026MB, JVM Mem    123MB
    58 Call,Free OS Mem   1026MB, JVM Mem    123MB
    59 Call,Free OS Mem   1026MB, JVM Mem    123MB
    60 Call,Free OS Mem   1026MB, JVM Mem    123MB
    61 Call,Free OS Mem    550MB, JVM Mem    123MB
    62 Call,Free OS Mem    462MB, JVM Mem    123MB
    63 Call,Free OS Mem    367MB, JVM Mem    123MB
    64 Call,Free OS Mem    282MB, JVM Mem    123MB
    65 Call,Free OS Mem    185MB, JVM Mem    123MB
    66 Call,Free OS Mem     92MB, JVM Mem    123MB
    67 Call,Free OS Mem     15MB, JVM Mem    123MB
    68 Call,Free OS Mem     15MB, JVM Mem    123MB
    69 Call,Free OS Mem     15MB, JVM Mem    123MB
    70 Call,Free OS Mem     15MB, JVM Mem    123MB
    71 Call,Free OS Mem    624MB, JVM Mem    123MB
    72 Call,Free OS Mem   1586MB, JVM Mem    123MB
    73 Call,Free OS Mem   1586MB, JVM Mem    123MB
    74 Call,Free OS Mem   1586MB, JVM Mem    123MB
    75 Call,Free OS Mem   1586MB, JVM Mem    123MB
    76 Call,Free OS Mem   1586MB, JVM Mem    123MB
    77 Call,Free OS Mem   1586MB, JVM Mem    123MB
    78 Call,Free OS Mem   1586MB, JVM Mem    123MB
    79 Call,Free OS Mem   1586MB, JVM Mem    123MB
    80 Call,Free OS Mem   1586MB, JVM Mem    123MB
    81 Call,Free OS Mem   2151MB, JVM Mem    123MB
    82 Call,Free OS Mem   2165MB, JVM Mem    123MB
    83 Call,Free OS Mem   2164MB, JVM Mem    123MB
    84 Call,Free OS Mem   2163MB, JVM Mem    123MB
    85 Call,Free OS Mem   2162MB, JVM Mem    123MB
    86 Call,Free OS Mem   2162MB, JVM Mem    123MB
    87 Call,Free OS Mem   2162MB, JVM Mem    123MB
    88 Call,Free OS Mem   2162MB, JVM Mem    123MB
    89 Call,Free OS Mem   2162MB, JVM Mem    123MB
    90 Call,Free OS Mem   2162MB, JVM Mem    123MB
    91 Call,Free OS Mem   2158MB, JVM Mem    123MB
    92 Call,Free OS Mem   2158MB, JVM Mem    123MB
    93 Call,Free OS Mem   2158MB, JVM Mem    123MB
    94 Call,Free OS Mem   2154MB, JVM Mem    123MB
    95 Call,Free OS Mem   2161MB, JVM Mem    123MB
    96 Call,Free OS Mem   2161MB, JVM Mem    123MB
    97 Call,Free OS Mem   2161MB, JVM Mem    123MB
    98 Call,Free OS Mem   2161MB, JVM Mem    123MB
    99 Call,Free OS Mem   2161MB, JVM Mem    123MB
    100Call,Free OS Mem   2161MB, JVM Mem    123MB
    Disconnected from the target VM, address: '127.0.0.1:53946', transport: 'socket'
    
    Process finished with exit code 0
    
    opened by yuebo 0
Releases(reflectasm-1.11.6)
Owner
Esoteric Software
Esoteric Software
An uber-fast parallelized Java classpath scanner and module scanner.

ClassGraph ClassGraph is an uber-fast parallelized classpath scanner and module scanner for Java, Scala, Kotlin and other JVM languages. ClassGraph wo

classgraph 2.4k Dec 29, 2022
Java runtime metadata analysis

Released org.reflections:reflections:0.9.12 - with support for Java 8 Reflections library has over 2.5 million downloads per month from Maven Central,

null 4.4k Dec 29, 2022
High performance Java reflection

Please use the ReflectASM discussion group for support. Overview ReflectASM is a very small Java library that provides high performance reflection by

Esoteric Software 1.4k Dec 31, 2022
A high available,high performance distributed messaging system.

#新闻 MetaQ 1.4.6.2发布。更新日志 MetaQ 1.4.6.1发布。更新日志 MetaQ 1.4.5.1发布。更新日志 MetaQ 1.4.5发布。更新日志 Meta-ruby 0.1 released: a ruby client for metaq. SOURCE #介绍 Meta

dennis zhuang 1.3k Dec 12, 2022
Simple API for using Java Reflection

Reflector По поводу багов или идей для данного репозитория можно писать в Discord или ВК(обратная связь) Обратная связь Discord: UnLegit#6190 ВКонтакт

null 1 Jan 25, 2022
BlackReflection provides a series of API to use Java Reflection easily.

BlackReflection provides a series of API to use Java Reflection easily. Developer can use annotation to assign class, field and method. Then it will generate the reflection code automatically, developer don't need to write extra code to achieve Java Reflection.

null 77 Dec 8, 2022
Annotation/Reflection Based Bukkit Command API. Containing many features such as help-service, command providers, tab completion, and many more!

CommandAPI Annotation/Reflection Based Command API that just does what you want it to do without any problems. Importing Maven <repository> <id>

damt 1 Jun 13, 2022
Lightweight reflection based tab library supporting 1.7 - 1.17 servers and clients.

Lightweight reflection based tab library supporting 1.7 - 1.17 servers and clients.

Gleeming 2 Aug 23, 2022
ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines web, high load, and cloud programming in Java, featuring ultimate performance and scalability!

Introduction ActiveJ is a full-featured modern Java platform, created from the ground up as an alternative to Spring/Micronauts/Netty/Jetty. It is des

ActiveJ LLC 579 Jan 7, 2023
Elegance, high performance and robustness all in one java bean mapper

JMapper Framework Fast as hand-written code with zero compromise. Artifact information Status Write the configuration using what you prefer: Annotatio

null 200 Dec 29, 2022
A high performance caching library for Java

Caffeine is a high performance, near optimal caching library. For more details, see our user's guide and browse the API docs for the latest release. C

Ben Manes 13k Jan 3, 2023
Lightweight, high performance Java caching

cache2k Java Caching cache2k is an in-memory high performance Java Caching library. Cache<String,String> cache = new Cache2kBuilder<String, String>(

null 672 Dec 16, 2022
High performance CSV reader and writer for Java.

FastCSV ?? FastCSV 2.0 upgrade has landed with major improvements on performance and usability! FastCSV is an ultra-fast and dependency-free RFC 4180

Oliver Siegmar 411 Dec 22, 2022
High Performance data structures and utility methods for Java

Agrona Agrona provides a library of data structures and utility methods that are a common need when building high-performance applications in Java. Ma

Real Logic 2.4k Dec 31, 2022
An Intuitive, Lightweight, High Performance Full Stack Java Web Framework.

mangoo I/O mangoo I/O is a Modern, Intuitive, Lightweight, High Performance Full Stack Java Web Framework. It is a classic MVC-Framework. The foundati

Sven Kubiak 52 Oct 31, 2022
Apache Dubbo is a high-performance, java based, open source RPC framework.

Apache Dubbo Project Apache Dubbo is a high-performance, Java-based open-source RPC framework. Please visit official site for quick start and document

The Apache Software Foundation 38.3k Jan 9, 2023
Apache Dubbo is a high-performance, java based, open source RPC framework.

Apache Dubbo Project Apache Dubbo is a high-performance, Java-based open-source RPC framework. Please visit official site for quick start and document

The Apache Software Foundation 38.2k Dec 31, 2022
High Performance data structures and utility methods for Java

Agrona Agrona provides a library of data structures and utility methods that are a common need when building high-performance applications in Java. Ma

Real Logic 2.5k Jan 5, 2023
A high performance caching library for Java

Caffeine is a high performance, near optimal caching library. For more details, see our user's guide and browse the API docs for the latest release. C

Ben Manes 13k Jan 5, 2023