Skip to content

Commit 40a9b9d

Browse files
committed
HHH-18410 Hoist some state to AbstractAttributeMapping to avoid megamorphic call sites
1 parent 73af6a0 commit 40a9b9d

File tree

4 files changed

+49
-60
lines changed

4 files changed

+49
-60
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java

+38-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
package org.hibernate.metamodel.mapping.internal;
88

99
import org.hibernate.metamodel.mapping.AttributeMapping;
10+
import org.hibernate.metamodel.mapping.AttributeMetadata;
1011
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
1112
import org.hibernate.metamodel.mapping.ManagedMappingType;
1213
import org.hibernate.metamodel.mapping.MappingType;
14+
import org.hibernate.property.access.spi.PropertyAccess;
1315
import org.hibernate.type.descriptor.java.JavaType;
1416

1517
/**
@@ -18,20 +20,39 @@
1820
public abstract class AbstractAttributeMapping implements AttributeMapping {
1921
private final String name;
2022
private final int fetchableIndex;
23+
private final int stateArrayPosition;
2124

2225
private final ManagedMappingType declaringType;
26+
private final AttributeMetadata attributeMetadata;
27+
private final PropertyAccess propertyAccess;
2328

24-
public AbstractAttributeMapping(String name, int fetchableIndex, ManagedMappingType declaringType) {
29+
public AbstractAttributeMapping(
30+
String name,
31+
int fetchableIndex,
32+
ManagedMappingType declaringType,
33+
AttributeMetadata attributeMetadata,
34+
int stateArrayPosition,
35+
PropertyAccess propertyAccess) {
2536
this.name = name;
2637
this.fetchableIndex = fetchableIndex;
2738
this.declaringType = declaringType;
39+
this.attributeMetadata = attributeMetadata;
40+
this.stateArrayPosition = stateArrayPosition;
41+
this.propertyAccess = propertyAccess;
2842
}
2943

3044
/**
3145
* For Hibernate Reactive
3246
*/
3347
protected AbstractAttributeMapping(AbstractAttributeMapping original) {
34-
this( original.name, original.fetchableIndex, original.declaringType );
48+
this(
49+
original.name,
50+
original.fetchableIndex,
51+
original.declaringType,
52+
original.attributeMetadata,
53+
original.stateArrayPosition,
54+
original.propertyAccess
55+
);
3556
}
3657

3758
@Override
@@ -44,6 +65,21 @@ public String getAttributeName() {
4465
return name;
4566
}
4667

68+
@Override
69+
public AttributeMetadata getAttributeMetadata() {
70+
return attributeMetadata;
71+
}
72+
73+
@Override
74+
public int getStateArrayPosition() {
75+
return stateArrayPosition;
76+
}
77+
78+
@Override
79+
public PropertyAccess getPropertyAccess() {
80+
return propertyAccess;
81+
}
82+
4783
@Override
4884
public int getFetchableKey() {
4985
return fetchableIndex;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractSingularAttributeMapping.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public abstract class AbstractSingularAttributeMapping
2222
extends AbstractStateArrayContributorMapping
2323
implements SingularAttributeMapping {
2424

25-
private final PropertyAccess propertyAccess;
26-
2725
public AbstractSingularAttributeMapping(
2826
String name,
2927
int stateArrayPosition,
@@ -32,8 +30,7 @@ public AbstractSingularAttributeMapping(
3230
FetchOptions mappedFetchOptions,
3331
ManagedMappingType declaringType,
3432
PropertyAccess propertyAccess) {
35-
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType );
36-
this.propertyAccess = propertyAccess;
33+
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType, propertyAccess );
3734
}
3835

3936
public AbstractSingularAttributeMapping(
@@ -45,21 +42,14 @@ public AbstractSingularAttributeMapping(
4542
FetchStyle fetchStyle,
4643
ManagedMappingType declaringType,
4744
PropertyAccess propertyAccess) {
48-
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType );
49-
this.propertyAccess = propertyAccess;
45+
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType, propertyAccess );
5046
}
5147

5248
/**
5349
* For Hibernate Reactive
5450
*/
5551
protected AbstractSingularAttributeMapping( AbstractSingularAttributeMapping original ) {
5652
super( original );
57-
this.propertyAccess = original.propertyAccess;
58-
}
59-
60-
@Override
61-
public PropertyAccess getPropertyAccess() {
62-
return propertyAccess;
6353
}
6454

6555
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java

+8-21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.hibernate.engine.FetchTiming;
1111
import org.hibernate.metamodel.mapping.AttributeMetadata;
1212
import org.hibernate.metamodel.mapping.ManagedMappingType;
13+
import org.hibernate.property.access.spi.PropertyAccess;
1314
import org.hibernate.sql.results.graph.FetchOptions;
1415

1516
/**
@@ -19,10 +20,8 @@ public abstract class AbstractStateArrayContributorMapping
1920
extends AbstractAttributeMapping
2021
implements FetchOptions {
2122

22-
private final AttributeMetadata attributeMetadata;
2323
private final FetchTiming fetchTiming;
2424
private final FetchStyle fetchStyle;
25-
private final int stateArrayPosition;
2625

2726
public AbstractStateArrayContributorMapping(
2827
String name,
@@ -31,12 +30,11 @@ public AbstractStateArrayContributorMapping(
3130
FetchStyle fetchStyle,
3231
int stateArrayPosition,
3332
int fetchableIndex,
34-
ManagedMappingType declaringType) {
35-
super( name, fetchableIndex, declaringType );
36-
this.attributeMetadata = attributeMetadata;
33+
ManagedMappingType declaringType,
34+
PropertyAccess propertyAccess) {
35+
super( name, fetchableIndex, declaringType, attributeMetadata, stateArrayPosition, propertyAccess );
3736
this.fetchTiming = fetchTiming;
3837
this.fetchStyle = fetchStyle;
39-
this.stateArrayPosition = stateArrayPosition;
4038
}
4139

4240
public AbstractStateArrayContributorMapping(
@@ -45,15 +43,17 @@ public AbstractStateArrayContributorMapping(
4543
FetchOptions mappedFetchOptions,
4644
int stateArrayPosition,
4745
int fetchableIndex,
48-
ManagedMappingType declaringType) {
46+
ManagedMappingType declaringType,
47+
PropertyAccess propertyAccess) {
4948
this(
5049
name,
5150
attributeMetadata,
5251
mappedFetchOptions.getTiming(),
5352
mappedFetchOptions.getStyle(),
5453
stateArrayPosition,
5554
fetchableIndex,
56-
declaringType
55+
declaringType,
56+
propertyAccess
5757
);
5858
}
5959

@@ -62,21 +62,8 @@ public AbstractStateArrayContributorMapping(
6262
*/
6363
protected AbstractStateArrayContributorMapping(AbstractStateArrayContributorMapping original) {
6464
super( original );
65-
this.attributeMetadata = original.attributeMetadata;
6665
this.fetchTiming = original.fetchTiming;
6766
this.fetchStyle = original.fetchStyle;
68-
this.stateArrayPosition = original.stateArrayPosition;
69-
}
70-
71-
72-
@Override
73-
public int getStateArrayPosition() {
74-
return stateArrayPosition;
75-
}
76-
77-
@Override
78-
public AttributeMetadata getAttributeMetadata() {
79-
return attributeMetadata;
8067
}
8168

8269
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java

+1-25
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ public interface Aware {
103103

104104
@SuppressWarnings("rawtypes")
105105
private final CollectionMappingType collectionMappingType;
106-
private final int stateArrayPosition;
107-
private final PropertyAccess propertyAccess;
108-
private final AttributeMetadata attributeMetadata;
109106
private final String referencedPropertyName;
110107
private final String mapKeyPropertyName;
111108

@@ -148,11 +145,8 @@ public PluralAttributeMappingImpl(
148145
ManagedMappingType declaringType,
149146
CollectionPersister collectionDescriptor,
150147
MappingModelCreationProcess creationProcess) {
151-
super( attributeName, fetchableIndex, declaringType );
152-
this.propertyAccess = propertyAccess;
153-
this.attributeMetadata = attributeMetadata;
148+
super( attributeName, fetchableIndex, declaringType, attributeMetadata, stateArrayPosition, propertyAccess );
154149
this.collectionMappingType = collectionMappingType;
155-
this.stateArrayPosition = stateArrayPosition;
156150
this.elementDescriptor = elementDescriptor;
157151
this.indexDescriptor = indexDescriptor;
158152
this.identifierDescriptor = identifierDescriptor;
@@ -215,10 +209,7 @@ public String getIndexPropertyName() {
215209
*/
216210
protected PluralAttributeMappingImpl(PluralAttributeMappingImpl original) {
217211
super( original );
218-
this.propertyAccess = original.propertyAccess;
219-
this.attributeMetadata = original.attributeMetadata;
220212
this.collectionMappingType = original.collectionMappingType;
221-
this.stateArrayPosition = original.stateArrayPosition;
222213
this.elementDescriptor = original.elementDescriptor;
223214
this.indexDescriptor = original.indexDescriptor;
224215
this.identifierDescriptor = original.identifierDescriptor;
@@ -381,21 +372,6 @@ public boolean containsTableReference(String tableExpression) {
381372
return tableExpression.equals( separateCollectionTable );
382373
}
383374

384-
@Override
385-
public int getStateArrayPosition() {
386-
return stateArrayPosition;
387-
}
388-
389-
@Override
390-
public AttributeMetadata getAttributeMetadata() {
391-
return attributeMetadata;
392-
}
393-
394-
@Override
395-
public PropertyAccess getPropertyAccess() {
396-
return propertyAccess;
397-
}
398-
399375
@Override
400376
public Generator getGenerator() {
401377
// can never be a generated value

0 commit comments

Comments
 (0)