From c6e042be24715541134fcadfb261e3be47f3cb35 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 22 Nov 2024 13:02:12 +0000 Subject: [PATCH 1/3] HHH-18875 Avoid need for refletive registrations triggered by StandardStack's custom implementation --- .../util/collections/StandardStack.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/StandardStack.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/StandardStack.java index 52c711453b8e..c27f5a973578 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/StandardStack.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/StandardStack.java @@ -4,7 +4,6 @@ */ package org.hibernate.internal.util.collections; -import java.lang.reflect.Array; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.function.BiFunction; @@ -21,24 +20,34 @@ * @author Marco Belladelli */ public final class StandardStack implements Stack { - private T[] elements; + + private Object[] elements; private int top = 0; - private Class type; + public StandardStack() { + } + public StandardStack(T initialValue) { + push( initialValue ); + } + + /** + * @deprecated use the default constructor instead + */ + @Deprecated(forRemoval = true) public StandardStack(Class type) { - this.type = type; } + /** + * @deprecated use {@link #StandardStack(Object)} instead. + */ + @Deprecated(forRemoval = true) public StandardStack(Class type, T initial) { - this( type ); push( initial ); } - @SuppressWarnings("unchecked") private void init() { - elements = (T[]) Array.newInstance( type, 8 ); - type = null; + elements = new Object[8]; } @Override @@ -57,7 +66,7 @@ public T pop() { if ( isEmpty() ) { throw new NoSuchElementException(); } - T e = elements[--top]; + T e = (T) elements[--top]; elements[top] = null; return e; } @@ -67,7 +76,7 @@ public T getCurrent() { if ( isEmpty() ) { return null; } - return elements[top - 1]; + return (T) elements[top - 1]; } @Override @@ -75,7 +84,7 @@ public T peek(int offsetFromTop) { if ( isEmpty() ) { return null; } - return elements[top - offsetFromTop - 1]; + return (T) elements[top - offsetFromTop - 1]; } @Override @@ -83,7 +92,7 @@ public T getRoot() { if ( isEmpty() ) { return null; } - return elements[0]; + return (T) elements[0]; } @Override @@ -107,14 +116,14 @@ public void clear() { @Override public void visitRootFirst(Consumer action) { for ( int i = 0; i < top; i++ ) { - action.accept( elements[i] ); + action.accept( (T) elements[i] ); } } @Override public X findCurrentFirst(Function function) { for ( int i = top - 1; i >= 0; i-- ) { - final X result = function.apply( elements[i] ); + final X result = function.apply( (T) elements[i] ); if ( result != null ) { return result; } @@ -125,7 +134,7 @@ public X findCurrentFirst(Function function) { @Override public X findCurrentFirstWithParameter(Y parameter, BiFunction biFunction) { for ( int i = top - 1; i >= 0; i-- ) { - final X result = biFunction.apply( elements[i], parameter ); + final X result = biFunction.apply( (T) elements[i], parameter ); if ( result != null ) { return result; } @@ -138,4 +147,5 @@ private void grow() { final int jump = ( oldCapacity < 64 ) ? ( oldCapacity + 2 ) : ( oldCapacity >> 1 ); elements = Arrays.copyOf( elements, oldCapacity + jump ); } + } From cac5fef4cb62eee8f4c32f0877dd62f5fea866e8 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 22 Nov 2024 13:07:38 +0000 Subject: [PATCH 2/3] HHH-18875 Avoid using the deprecated constructors of StandardStack --- .../hibernate/graph/internal/parse/GraphParser.java | 6 +++--- .../query/hql/internal/SemanticQueryBuilder.java | 5 ++--- .../internal/DomainResultCreationStateImpl.java | 2 +- .../query/sqm/sql/BaseSqmToSqlAstConverter.java | 12 ++++++------ .../sql/ast/spi/AbstractSqlAstTranslator.java | 6 +++--- .../sql/results/graph/DomainResultGraphPrinter.java | 2 +- .../org/hibernate/sql/results/spi/LoadContexts.java | 2 +- .../hibernate/orm/test/util/StandardStackTest.java | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java index 2c8d463a8a5a..5697f5bd3d78 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java @@ -64,9 +64,9 @@ public static void parseInto( private final SessionFactoryImplementor sessionFactory; - private final Stack graphStack = new StandardStack<>( GraphImplementor.class ); - private final Stack attributeNodeStack = new StandardStack<>( AttributeNodeImplementor.class ); - private final Stack graphSourceStack = new StandardStack<>(SubGraphGenerator.class); + private final Stack graphStack = new StandardStack<>(); + private final Stack attributeNodeStack = new StandardStack<>(); + private final Stack graphSourceStack = new StandardStack<>(); public GraphParser(SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 8500c7ffb3f7..fe3ea457f2ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -308,8 +308,8 @@ public static SqmStatement buildSemanticModel( private final Stack dotIdentifierConsumerStack; - private final Stack parameterDeclarationContextStack = new StandardStack<>( ParameterDeclarationContext.class ); - private final Stack processingStateStack = new StandardStack<>( SqmCreationProcessingState.class ); + private final Stack parameterDeclarationContextStack = new StandardStack<>(); + private final Stack processingStateStack = new StandardStack<>(); private final BasicDomainType integerDomainType; private final JavaType> listJavaType; @@ -382,7 +382,6 @@ private SemanticQueryBuilder( this.creationContext = creationContext; this.query = query; this.dotIdentifierConsumerStack = new StandardStack<>( - DotIdentifierConsumer.class, new BasicDotIdentifierConsumer( this ) ); this.parameterStyle = creationOptions.useStrictJpaCompliance() diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/internal/DomainResultCreationStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/results/internal/DomainResultCreationStateImpl.java index c7ee3c7740cf..e7e5f7d8b68b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/internal/DomainResultCreationStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/internal/DomainResultCreationStateImpl.java @@ -77,7 +77,7 @@ public class DomainResultCreationStateImpl private final LegacyFetchResolver legacyFetchResolver; private final SessionFactoryImplementor sessionFactory; - private final Stack fetchBuilderResolverStack = new StandardStack<>( Function.class, fetchableName -> null ); + private final Stack fetchBuilderResolverStack = new StandardStack<>( fetchableName -> null ); private Map registeredLockModes; private boolean processingKeyFetches = false; private boolean resolvingCircularFetch; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 6a9163094f5a..3bd91f0e97e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -488,7 +488,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base private boolean deduplicateSelectionItems; private ForeignKeyDescriptor.Nature currentlyResolvingForeignKeySide; private SqmStatement currentSqmStatement; - private Stack sqmQueryPartStack = new StandardStack<>( SqmQueryPart.class ); + private Stack sqmQueryPartStack = new StandardStack<>(); private CteContainer cteContainer; /** * A map from {@link SqmCteTable#getCteName()} to the final SQL name. @@ -506,8 +506,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base private List> orderByFragments; private final SqlAliasBaseManager sqlAliasBaseManager = new SqlAliasBaseManager(); - private final Stack processingStateStack = new StandardStack<>( SqlAstProcessingState.class ); - private final Stack fromClauseIndexStack = new StandardStack<>( FromClauseIndex.class ); + private final Stack processingStateStack = new StandardStack<>(); + private final Stack fromClauseIndexStack = new StandardStack<>(); // Captures all entity name uses under which a table group is being used within the current conjunct. // Outside a top level conjunct, it represents the "global uses" i.e. select, from, group and order by clauses. @@ -521,9 +521,9 @@ public abstract class BaseSqmToSqlAstConverter extends Base private SqmJoin currentlyProcessingJoin; protected Predicate additionalRestrictions; - private final Stack currentClauseStack = new StandardStack<>( Clause.class ); - private final Stack inferrableTypeAccessStack = new StandardStack<>( Supplier.class ); - private final Stack queryTransformers = new StandardStack<>( List.class ); + private final Stack currentClauseStack = new StandardStack<>(); + private final Stack inferrableTypeAccessStack = new StandardStack<>(); + private final Stack queryTransformers = new StandardStack<>(); private boolean inTypeInference; private boolean inImpliedResultTypeInference; private boolean inNestedContext; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index 516ab521f286..d9096e88e556 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -304,9 +304,9 @@ public abstract class AbstractSqlAstTranslator implemen private final ParameterMarkerStrategy parameterMarkerStrategy; - private final Stack clauseStack = new StandardStack<>( Clause.class ); - private final Stack queryPartStack = new StandardStack<>( QueryPart.class ); - private final Stack statementStack = new StandardStack<>( Statement.class ); + private final Stack clauseStack = new StandardStack<>(); + private final Stack queryPartStack = new StandardStack<>(); + private final Stack statementStack = new StandardStack<>(); private final Dialect dialect; private final Set affectedTableNames = new HashSet<>(); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/DomainResultGraphPrinter.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/DomainResultGraphPrinter.java index dd272270a0b7..3a50c6629b45 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/DomainResultGraphPrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/DomainResultGraphPrinter.java @@ -45,7 +45,7 @@ public static void logDomainResultGraph(String header, List> dom } private final StringBuilder buffer; - private final Stack fetchParentStack = new StandardStack<>( FetchParent.class ); + private final Stack fetchParentStack = new StandardStack<>(); private DomainResultGraphPrinter(String header) { buffer = new StringBuilder( header + ":" + System.lineSeparator() ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java index 90dc0738fd5d..44a95421d23b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java @@ -24,7 +24,7 @@ public class LoadContexts { private static final CoreMessageLogger log = CoreLogging.messageLogger( LoadContexts.class ); private final PersistenceContext persistenceContext; - private final StandardStack jdbcValuesSourceProcessingStateStack = new StandardStack<>( JdbcValuesSourceProcessingState.class ); + private final StandardStack jdbcValuesSourceProcessingStateStack = new StandardStack<>(); public LoadContexts(PersistenceContext persistenceContext) { this.persistenceContext = persistenceContext; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/util/StandardStackTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/util/StandardStackTest.java index 8de2c1b92525..7a9bb2fe20fa 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/util/StandardStackTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/util/StandardStackTest.java @@ -146,7 +146,7 @@ public void testFindCurrentFirstWithParameterCleared() { // utility functions private Stack allocateStack(int size) { - final Stack stack = new StandardStack<>( Integer.class ); + final Stack stack = new StandardStack<>(); for ( int i = 0; i < size; i++ ) { stack.push( i ); } From 17bdead83fa9a47fa74a6bcc5e4d52abb1f97f76 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 22 Nov 2024 13:10:22 +0000 Subject: [PATCH 3/3] HHH-18875 Remove the related GraalVM reflective registrations --- .../graalvm/internal/StaticClassLists.java | 36 ------------------- .../internal/StaticClassListsTest.java | 22 +----------- 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java b/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java index dc0942b293e1..a67dd6cd3524 100644 --- a/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java +++ b/hibernate-graalvm/src/main/java/org/hibernate/graalvm/internal/StaticClassLists.java @@ -4,24 +4,7 @@ */ package org.hibernate.graalvm.internal; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.function.Supplier; -import org.hibernate.graph.internal.parse.SubGraphGenerator; -import org.hibernate.graph.spi.AttributeNodeImplementor; -import org.hibernate.graph.spi.GraphImplementor; -import org.hibernate.query.hql.spi.DotIdentifierConsumer; -import org.hibernate.query.hql.spi.SqmCreationProcessingState; -import org.hibernate.query.sqm.spi.ParameterDeclarationContext; -import org.hibernate.query.sqm.sql.FromClauseIndex; -import org.hibernate.sql.ast.Clause; -import org.hibernate.sql.ast.spi.SqlAstProcessingState; -import org.hibernate.sql.ast.tree.Statement; -import org.hibernate.sql.ast.tree.select.QueryPart; -import org.hibernate.sql.results.graph.FetchParent; -import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState; import org.hibernate.tool.schema.internal.script.MultiLineSqlScriptExtractor; import org.hibernate.type.EnumType; @@ -94,25 +77,6 @@ public static Class[] typesNeedingArrayCopy() { org.hibernate.event.spi.PostCollectionRecreateEventListener[].class, org.hibernate.event.spi.PostCollectionRemoveEventListener[].class, org.hibernate.event.spi.PostCollectionUpdateEventListener[].class, - //And other array types, necessary for allocation of generified instances of org.hibernate.internal.util.collections.StandardStack: - //TODO can this list be tested for consistency with the core module? Or generated? e.g. could use Jandex? - AttributeNodeImplementor[].class, - Clause[].class, - DotIdentifierConsumer[].class, - FetchParent[].class, - FromClauseIndex[].class, - Function[].class, - GraphImplementor[].class, - JdbcValuesSourceProcessingState[].class, - List[].class, - Map.Entry[].class, - ParameterDeclarationContext[].class, - QueryPart[].class, - SqlAstProcessingState[].class, - SqmCreationProcessingState[].class, - Statement[].class, - SubGraphGenerator[].class, - Supplier[].class, }; } diff --git a/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java b/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java index dac75c6ba277..056e88d50753 100644 --- a/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java +++ b/hibernate-graalvm/src/test/java/org/hibernate/graalvm/internal/StaticClassListsTest.java @@ -158,27 +158,7 @@ Stream> classes() { // Putting anything here is running the risk of forgetting // why it was necessary in the first place... return Stream.of( - // Java classes -- the why is lost to history - java.util.function.Function[].class, - java.util.List[].class, - java.util.Map.Entry[].class, - java.util.function.Supplier[].class, - // Graphs -- the why is lost to history - org.hibernate.graph.spi.AttributeNodeImplementor[].class, - org.hibernate.sql.results.graph.FetchParent[].class, - org.hibernate.graph.spi.GraphImplementor[].class, - org.hibernate.graph.internal.parse.SubGraphGenerator[].class, - // AST/parsing -- no way to detect this automatically, you just have to know. - org.hibernate.sql.ast.Clause[].class, - org.hibernate.query.hql.spi.DotIdentifierConsumer[].class, - org.hibernate.query.sqm.sql.FromClauseIndex[].class, - org.hibernate.query.sqm.spi.ParameterDeclarationContext[].class, - org.hibernate.sql.ast.tree.select.QueryPart[].class, - org.hibernate.sql.ast.spi.SqlAstProcessingState[].class, - org.hibernate.query.hql.spi.SqmCreationProcessingState[].class, - org.hibernate.sql.ast.tree.Statement[].class, - // Various internals -- the why is lost to history - org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState[].class + // Hopefully to remain empty ); } };