-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bytebuddy cogen, removed cglib (java 17) (#1737)
- Loading branch information
Showing
26 changed files
with
182 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-Xmx3G | ||
-Xmx12G | ||
-XX:ReservedCodeCacheSize=256M | ||
-XX:MaxMetaspaceSize=2560M | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tions/CgLibInstantiationOpException.scala → ...etation/ProxyInstantiationException.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package izumi.distage.provisioning.strategies.cglib.exceptions | ||
package izumi.distage.model.exceptions.interpretation | ||
|
||
import izumi.distage.model.exceptions.DIException | ||
import izumi.distage.model.plan.ExecutableOp | ||
import izumi.distage.model.provisioning.proxies.ProxyProvider.ProxyParams | ||
|
||
class CgLibInstantiationOpException(message: String, val target: Class[?], val params: ProxyParams, val op: ExecutableOp, cause: Throwable) | ||
class ProxyInstantiationException(message: String, val target: Class[?], val params: ProxyParams, val op: ExecutableOp, cause: Throwable) | ||
extends DIException(message, cause) |
2 changes: 1 addition & 1 deletion
2
...oning/strategies/cglib/DistageProxy.scala → ...l/provisioning/proxies/DistageProxy.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 12 additions & 13 deletions
25
...gies/cglib/CglibAtomicRefDispatcher.scala → ...yproxy/ByteBuddyAtomicRefDispatcher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
...es/cglib/CglibNullMethodInterceptor.scala → ...roxy/ByteBuddyNullMethodInterceptor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../main/scala/izumi/distage/provisioning/strategies/dynamicproxy/DynamicProxyProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package izumi.distage.provisioning.strategies.dynamicproxy | ||
|
||
import izumi.distage.model.exceptions.interpretation.ProxyInstantiationException | ||
import izumi.distage.model.provisioning.proxies.ProxyProvider.ProxyParams.{Empty, Params} | ||
import izumi.distage.model.provisioning.proxies.ProxyProvider.{DeferredInit, ProxyContext} | ||
import izumi.distage.model.provisioning.proxies.{DistageProxy, ProxyProvider} | ||
import izumi.distage.model.reflection.DIKey | ||
import izumi.distage.provisioning.strategies.bytebuddyproxy.{ByteBuddyAtomicRefDispatcher, ByteBuddyNullMethodInterceptor} | ||
import net.bytebuddy.ByteBuddy | ||
import net.bytebuddy.dynamic.scaffold.TypeValidation | ||
import net.bytebuddy.implementation.InvocationHandlerAdapter | ||
import net.bytebuddy.matcher.{ElementMatcher, ElementMatchers} | ||
import izumi.fundamentals.platform.exceptions.IzThrowable.* | ||
import net.bytebuddy.description.method.MethodDescription | ||
|
||
import java.lang.reflect.InvocationHandler | ||
|
||
object DynamicProxyProvider extends ProxyProvider { | ||
|
||
override def makeCycleProxy(deferredKey: DIKey, proxyContext: ProxyContext): DeferredInit = { | ||
val nullDispatcher = new ByteBuddyNullMethodInterceptor(deferredKey) | ||
val nullProxy = mkDynamic(nullDispatcher, proxyContext) | ||
|
||
val realDispatcher = new ByteBuddyAtomicRefDispatcher(nullProxy) | ||
val realProxy = mkDynamic(realDispatcher, proxyContext) | ||
|
||
DeferredInit(realDispatcher, realProxy) | ||
} | ||
|
||
private def mkDynamic(dispatcher: InvocationHandler, proxyContext: ProxyContext): AnyRef = { | ||
val clazz = proxyContext.runtimeClass.asInstanceOf[Class[AnyRef]] | ||
|
||
val constructedProxyClass: Class[AnyRef] = new ByteBuddy() | ||
.`with`(TypeValidation.DISABLED) | ||
.subclass(clazz) | ||
.method(ElementMatchers.isMethod.asInstanceOf[ElementMatcher[MethodDescription]]) | ||
.intercept(InvocationHandlerAdapter.of(dispatcher)) | ||
.implement(classOf[DistageProxy]) | ||
.make() | ||
.load(clazz.getClassLoader) | ||
.getLoaded.asInstanceOf[Class[AnyRef]] | ||
|
||
try { | ||
proxyContext.params match { | ||
case Empty => | ||
constructedProxyClass.getDeclaredConstructor().newInstance() | ||
case Params(types, values) => | ||
val c = constructedProxyClass.getDeclaredConstructor(types: _*) | ||
c.newInstance(values.map(_.asInstanceOf[AnyRef]): _*) | ||
} | ||
} catch { | ||
case f: Throwable => | ||
throw new ProxyInstantiationException( | ||
s"Failed to instantiate class with CGLib, make sure you don't dereference proxied parameters in constructors: " + | ||
s"class=${proxyContext.runtimeClass}, params=${proxyContext.params}, exception=${f.stackTrace}", | ||
clazz, | ||
proxyContext.params, | ||
proxyContext.op, | ||
f, | ||
) | ||
} | ||
} | ||
} |
File renamed without changes.
59 changes: 0 additions & 59 deletions
59
...cglib/src/main/scala/izumi/distage/provisioning/strategies/cglib/CglibProxyProvider.scala
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
distage/distage-core/.js/src/main/scala/izumi/distage/bootstrap/CglibBootstrap.scala
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
distage/distage-core/.js/src/main/scala/izumi/distage/bootstrap/DynamicProxyBootstrap.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package izumi.distage.bootstrap | ||
|
||
import izumi.distage.model.provisioning.proxies.ProxyProvider | ||
import izumi.distage.model.provisioning.proxies.ProxyProvider.ProxyProviderFailingImpl | ||
|
||
object DynamicProxyBootstrap { | ||
val DynamicProxyProvider: ProxyProvider = ProxyProviderFailingImpl | ||
} |
7 changes: 0 additions & 7 deletions
7
distage/distage-core/.jvm/src/main/scala/izumi/distage/bootstrap/CglibBootstrap.scala
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
distage/distage-core/.jvm/src/main/scala/izumi/distage/bootstrap/DynamicProxyBootstrap.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package izumi.distage.bootstrap | ||
|
||
import izumi.distage.model.provisioning.proxies.ProxyProvider | ||
import izumi.fundamentals.reflection.TypeUtil | ||
|
||
import scala.util.Try | ||
|
||
object DynamicProxyBootstrap { | ||
val dynProxyProviderName = "izumi.distage.provisioning.strategies.dynamicproxy.DynamicProxyProvider$" | ||
|
||
val DynamicProxyProvider: ProxyProvider = | ||
Try(TypeUtil.instantiateObject[ProxyProvider](Class.forName(dynProxyProviderName))).toOption match { | ||
case Some(value) => | ||
value | ||
case None => | ||
import izumi.distage.model.provisioning.proxies.ProxyProvider.ProxyProviderFailingImpl | ||
ProxyProviderFailingImpl | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.