Commit Graph

2990 Commits

Author SHA1 Message Date
Brian Clozel fc47d25bc7 Polish
See gh-26320
2022-09-02 10:55:40 +02:00
Sam Brannen 73abd58202 Polishing 2022-09-02 10:23:53 +02:00
Phillip Webb 505da5c602 Migrate hint registration to shortcuts
Migrate code to make use of the `MemberCategory` and `FieldMode`
shortcuts.

See gh-29011
2022-09-01 17:26:06 -07:00
Phillip Webb bc0bf1fac3 Add additional shortcuts for hint registration
Add `MemberCategory` and `FieldMode` shortcuts for type registration.
Helper `builtWith` methods have also been extracted to the Hint types
to allow general reuse (for example with `registerTypes`).

See gh-29011
2022-09-01 17:25:46 -07:00
Phillip Webb da1005cd66 Add FieldMode for field hints and ensure that it cannot be downgraded
Add a `FieldMode` enum analogous to `ExecutableHint` and update
`FieldHint` to ensure that registration cannot downgrade `WRITE`
to `READ`.

Fixes gh-29055
2022-09-01 17:25:43 -07:00
Phillip Webb 0bd923b0a7 Polishing 2022-09-01 16:28:02 -07:00
Phillip Webb cea06e6a9e Polish ReflectionHints and TypeHint method order 2022-09-01 16:27:54 -07:00
Phillip Webb cfd37d948d Reduce visibility of hint factory methods
Reduce the visibility of hint factory methods that return a `Builder`.
Since the `build()` method of the `Builder` is package-private the
factory methods can also be package-private.
2022-09-01 13:37:08 -07:00
Sam Brannen a5584dcaa6 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
2022-09-01 17:44:24 +02:00
Sam Brannen 6a68bd58f9 Introduce AnnotationUtils.isSynthesizedAnnotation(Annotation)
Since SynthesizedAnnotation will be deprecated (and potentially
completely removed) in Spring Framework 6.0, this commit introduces
AnnotationUtils.isSynthesizedAnnotation(Annotation) in 5.3.x to allow
people to migrate away from relying on SynthesizedAnnotation.

Closes gh-29054
2022-09-01 17:35:22 +02:00
Sam Brannen b1414bf15b Polishing 2022-09-01 17:23:04 +02:00
Brian Clozel c470262c8e Rewrite ConcurrentLruCache implementation
Prior to this commit, the `ConcurrentLruCache` implementation would not
perform well under certain conditions. As long as the cache capacity was
not reached, the cache would avoid maintaining an eviction queue
(reordering entries depending with least/most recently read). When the
cache capacity was reached, the LRU queue was updated for each
read/write operation. This decreased performance significantly under
contention when the capacity was reached.

This commit completely rewrites the internals of `ConcurrentLruCache`.
`ConcurrentLruCache` is now a specialized version of the
`ConcurrentLinkedHashMap` [1]. This change focuses on buferring read and
write operations, only processing them at certain times to avoid
contention.

When a cached entry is read, a read operation is queued and buffered
operations are drained if the buffer reached a fixed limit. When a new
cache entry is added or removed, a write operation is queued and
triggers a drain attempt. When the capacity is outgrown, the cache polls
items from the eviction queue, which maintains elements with the
least recently used ones first. Entries are removed until the capacity
is under control.

The behavior described here and the buffer sizes are optimized with the
number of available processors in mind. Work is localized as much as
possible on a per-thread basis to avoid contention on the eviction queue.

The new implementation has been tested with the JMH benchmark provided
here, comparing the former `COncurrentLruCache`, the new implementation
as well as the `ConcurrentLinkedHashMap` [1].

When testing with a cache reaching capacity, under contention, with a
10% cache miss, we're seeing a 40x improvement compared to the previous
implementation and performance on par with the reference.
See [2] for how to replicate the benchmark.

[1] https://github.com/ben-manes/concurrentlinkedhashmap
[2] https://github.com/spring-projects/spring-framework/wiki/Micro-Benchmarks

Closes gh-26320
2022-08-31 19:10:50 +02:00
Johnny Lim 706c1ec8dd Polish 2022-08-31 23:59:51 +09:00
Brian Clozel f877f81ae4 Move Netty 5 dependency to Framework platform 2022-08-30 21:58:41 +02:00
Sam Brannen b50415062b Clean up warnings and polish tests
This commit also modifies ResourceWebHandlerTests.getResourceFromFileSystem()
so that it passes in the IDE.
2022-08-26 15:20:16 +02:00
Sébastien Deleuze d16fa82888 Remove remaining native build-time class initializations
See oracle/graal#4673 related issue.

Closes gh-29018
2022-08-26 09:29:17 +02:00
Sébastien Deleuze 3e9b57106e Refine TypeHint.Builder#onReachableType Javadoc 2022-08-26 08:35:18 +02:00
Sébastien Deleuze 08f636b691 Introduce TypeHint.Builder#onReachableType(Class<?>)
Closes gh-29017
2022-08-26 08:34:54 +02:00
Arjen Poutsma 626739d93f Polishing 2022-08-25 11:31:47 +02:00
Arjen Poutsma 9c33d2707a Introduce support for Netty 5 Buffer
This commit introduces support for Netty 5's Buffer, in the form of
Netty5DataBuffer. Because of the new API offered by Buffer, several
changes have been made to the DataBuffer API:

- CloseableDataBuffer is a simpler alternative to PooledDataBuffer, and
  implemented by Netty5DataBuffer. DataBufferUtils::release can now
  handle CloseableDataBuffer as well as PooledDataBuffer.
- PooledDataBuffer::touch has been moved into a separate interface:
  TouchableDataBuffer, which is implemented by Netty5DataBuffer.
- The capacity of DataBuffers can no longer be reduced, they can only
  grow larger. As a consequence, DataBuffer::capacity(int) has been
  deprecated, but ensureWritable (formally ensureCapacity) still exists.
- DataBuffer::slice and retainedSlice have been deprecated in favor of
  split, a new method that ensures that memory regions do not overlap.
- DataBuffer::asByteBuffer has been deprecated in favor of toByteBuffer,
  a new method that returns a copy, instead of shared data.
- DataBufferFactory::allocateBuffer has been deprecated in favor of
  allocateBuffer(int).

Closes gh-28874
2022-08-25 11:00:22 +02:00
Stephane Nicoll 7ca57b7e80 Use consistent registration API in TypeHint.Builder
This commit adapts the registration of fields, constructors, and methods
to provide the same convenience than the reflection-based one available
in ReflectionHints.

See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll 5aa8583159 Add shortcut to register an executable with a mode
See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll c164b918c0 Apply consistent RuntimeHints defaults
This commit harmonizes the registration of an executable so that
the default method and the method that takes an empty customizer
produces the same hint. The same applies to the readable flag of
a field hint.

Rather than returning a list of executable modes, the "highest" mode
is retained.

See gh-29011
2022-08-24 19:32:01 +02:00
Sam Brannen e5f9bb76b1 Declare covariant return type in DefaultGenerationContext.withName()
Prior to this commit, if infrastructure code working directly with an
instance of DefaultGenerationContext invoked withName() on that
instance, the new GenerationContext had to be cast from
GenerationContext to DefaultGenerationContext in order for the
infrastructure to continue working with the DefaultGenerationContext
API -- for example, the writeGeneratedContent() method which is not
defined in the GenerationContext API.

This commit makes use of a covariant return type by declaring that
DefaultGenerationContext.withName() returns a DefaultGenerationContext.
2022-08-22 16:41:20 +02:00
Sam Brannen 9ab046bdbb Introduce complete DefaultGenerationContext constructor
Prior to this commit, it was possible to create a DefaultGenerationContext
based on a ClassNameGenerator and GeneratedFiles; however, there was no way
to create a DefaultGenerationContext that reused an existing RuntimeHints
instance which is necessary in certain use cases -- for example, in the
TestContext framework where multiple GenerationContexts are created
based on shared instances of GeneratedFiles and RuntimeHints.

This commit addresses this by introducing a public
DefaultGenerationContext(ClassNameGenerator,GeneratedFiles,RuntimeHints)
constructor.
2022-08-22 16:41:11 +02:00
Stephane Nicoll 40de029bf8 Polish 2022-08-22 16:32:53 +02:00
Stephane Nicoll eac616a83e Restore support for package private ReflectiveProcessor
See gh-28975
2022-08-18 14:27:59 +02:00
Stephane Nicoll d6afa8df2d Improve registration of the same hint for multiple classes
Based on the feedback in #28977 an easy way to create a list of
type references based on a vararg of classes is helpful when
registering the same hints for several types.
2022-08-18 06:52:34 +02:00
Stephane Nicoll 4556895e6e Expose registrar for @Reflective
This commit exposes the logic of processing `@Reflective` on beans so
that it can be reused in custom arrangements.

Closes gh-28975
2022-08-17 14:33:09 +02:00
Stephane Nicoll 9846d28ae6 Remove support for declaring class proxies hints
Closes gh-28972
2022-08-17 09:25:03 +02:00
Stephane Nicoll f4389c3114 Restore ANNOTATION_HINT in a deprecated form for the time being 2022-08-16 16:18:04 +02:00
Stephane Nicoll 4f0c879778 Rationalize hints required for annotations
This commit updates RuntimeHintsUtils to focus on registering a JDK
proxy only as annotations of annotated elements that have at least
an introspection hints are visible out-of-the-box.

This commit also removes unnecessary hints and adapt `@Reflective` to
detect if a hint is required using the introduced
MergedAnnotation#isSynthesizable.

See gh-28967
2022-08-16 15:42:52 +02:00
Stephane Nicoll 32346b8382 Introduce isSynthesizable in MergedAnnotation
This commit adds the ability to check if a the annotation managed by
a MergedAnnotation is synthesizable. This makes it easier to register
a JDK proxy hint if necessary

See gh-28967
2022-08-16 15:42:52 +02:00
Sam Brannen 653552aa6f Make DefaultGenerationContext(GeneratedClasses,...) package private
The DefaultGenerationContext constructor which accepts an instance of
GeneratedClasses is now package private since GeneratedClasses can only
be created within the `org.springframework.aot.generate` package.
2022-08-16 12:06:40 +02:00
Sam Brannen 36fa8bd26b Remove unused constructors in TestGenerationContext 2022-08-16 12:06:40 +02:00
Arjen Poutsma ef178d24ec Merge branch '5.3.x' 2022-08-16 11:24:01 +02:00
Arjen Poutsma 7e7d6b9c3a Propagate Context in DataBufferUtils::write(Path)
This commit makes sure that the Reactor context is propagated in
DataBufferUtils::write(Path).

Closes gh-28933
See gh-27517
2022-08-16 11:21:12 +02:00
Sam Brannen c58c827291 Polishing 2022-08-15 19:53:21 +02:00
Sam Brannen 40f9fe0874 Make eclipse task for spring-core depend on JavaPoet and Objenesis tasks 2022-08-13 16:18:34 +02:00
Sam Brannen d6d629a8eb Clean up warnings in CGLIB fork 2022-08-13 16:03:28 +02:00
Stephane Nicoll 7c2453c373 Integrate class proxy generation in AOT processing
This commit updates ApplicationContextAotGenerator to register a
handler that process Cglib generated classes. The handler registers
such classes to the GeneratedFiles and provide a hint so that it
can be instantiated using reflection.

Closes gh-28954
2022-08-12 12:17:13 +02:00
Juergen Hoeller d6f73994c2 Fix malformed HTML in CGLIB javadoc
See gh-28955
2022-08-12 12:14:18 +02:00
Juergen Hoeller 7fa5b8dcb5 Turn CGLIB patch into full CGLIB fork in spring-core
Closes gh-28955
2022-08-12 11:38:43 +02:00
Sam Brannen a052f9a34e Polishing 2022-08-11 20:43:35 +02:00
Sam Brannen 7631a09405 Do not register SynthesizedAnnotation proxy for @AliasFor
Closes gh-28953
2022-08-11 20:32:03 +02:00
Sam Brannen 0207f3a55f Polishing 2022-08-11 19:41:56 +02:00
Stephane Nicoll d1abdff89c Merge branch '5.3.x' 2022-08-11 10:44:33 +02:00
Stephane Nicoll 6806aaf162 Polish "Add missing TreeSet to CollectionFactory.createCollection()"
See gh-28949
2022-08-11 08:28:43 +02:00
Johnny Lim ccec75c98d Add missing TreeSet to CollectionFactory.createCollection()
See gh-28949
2022-08-11 08:22:11 +02:00
Juergen Hoeller b31a15851e Support for pre-generated CGLIB proxy classes (in AOT scenarios)
Includes runtime storing of generated classes to a directory specified by the "cglib.generatedClasses" system property. Avoids lazy CGLIB fast-class generation and replaces generated Enhancer and MethodWrapper key classes with equivalent record types. Introduces support for early type determination in InstantiationStrategy, AopProxy and SmartInstantiationAwareBeanPostProcessor - in order to trigger CGLIB class generation in refreshForAotProcessing (through early determineBeanType calls for bean definitions).

Closes gh-28115
2022-08-10 23:30:19 +02:00