1
1
/*
2
- * Copyright (c) 2014, 2017 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2014, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -113,12 +113,17 @@ public static void postWriteBarrierStub(Object object) {
113
113
private static native void callPostWriteBarrierStub (@ ConstantNodeParameter ForeignCallDescriptor descriptor , Object object );
114
114
115
115
@ Snippet
116
- public static void postWriteBarrierSnippet (Object object , @ ConstantParameter boolean shouldOutline , @ ConstantParameter boolean alwaysAlignedChunk , @ ConstantParameter boolean verifyOnly ) {
116
+ public static void postWriteBarrierSnippet (Object object , @ ConstantParameter boolean shouldOutline , @ ConstantParameter boolean alwaysAlignedChunk , @ ConstantParameter boolean eliminated ) {
117
+ boolean shouldVerify = SerialGCOptions .VerifyWriteBarriers .getValue ();
118
+ if (!shouldVerify && eliminated ) {
119
+ return ;
120
+ }
121
+
117
122
Object fixedObject = FixedValueAnchorNode .getObject (object );
118
123
ObjectHeader oh = Heap .getHeap ().getObjectHeader ();
119
124
UnsignedWord objectHeader = oh .readHeaderFromObject (fixedObject );
120
125
121
- if (SerialGCOptions . VerifyWriteBarriers . getValue () && alwaysAlignedChunk ) {
126
+ if (shouldVerify && alwaysAlignedChunk ) {
122
127
/*
123
128
* To increase verification coverage, we do the verification before checking if a
124
129
* barrier is needed at all.
@@ -136,20 +141,20 @@ public static void postWriteBarrierSnippet(Object object, @ConstantParameter boo
136
141
return ;
137
142
}
138
143
139
- if (shouldOutline && !verifyOnly ) {
144
+ if (shouldOutline && !eliminated ) {
140
145
callPostWriteBarrierStub (POST_WRITE_BARRIER , fixedObject );
141
146
return ;
142
147
}
143
148
144
149
if (!alwaysAlignedChunk ) {
145
150
boolean unaligned = ObjectHeaderImpl .isUnalignedHeader (objectHeader );
146
151
if (BranchProbabilityNode .probability (BranchProbabilityNode .NOT_LIKELY_PROBABILITY , unaligned )) {
147
- RememberedSet .get ().dirtyCardForUnalignedObject (fixedObject , verifyOnly );
152
+ RememberedSet .get ().dirtyCardForUnalignedObject (fixedObject , eliminated );
148
153
return ;
149
154
}
150
155
}
151
156
152
- RememberedSet .get ().dirtyCardForAlignedObject (fixedObject , verifyOnly );
157
+ RememberedSet .get ().dirtyCardForAlignedObject (fixedObject , eliminated );
153
158
}
154
159
155
160
private class PostWriteBarrierLowering implements NodeLoweringProvider <WriteBarrierNode > {
@@ -179,7 +184,7 @@ public void lower(WriteBarrierNode barrier, LoweringTool tool) {
179
184
args .add ("object" , address .getBase ());
180
185
args .add ("shouldOutline" , shouldOutline (barrier ));
181
186
args .add ("alwaysAlignedChunk" , alwaysAlignedChunk );
182
- args .add ("verifyOnly " , getVerifyOnly (barrier ));
187
+ args .add ("eliminated " , tryEliminate (barrier ));
183
188
184
189
template (tool , barrier , args ).instantiate (tool .getMetaAccess (), barrier , SnippetTemplate .DEFAULT_REPLACER , args );
185
190
}
@@ -188,12 +193,17 @@ private static boolean shouldOutline(WriteBarrierNode barrier) {
188
193
if (SerialGCOptions .OutlineWriteBarriers .getValue () != null ) {
189
194
return SerialGCOptions .OutlineWriteBarriers .getValue ();
190
195
}
191
- return GraalOptions .ReduceCodeSize .getValue (barrier .getOptions ());
196
+ if (GraalOptions .ReduceCodeSize .getValue (barrier .getOptions ())) {
197
+ return true ;
198
+ }
199
+ // Newly allocated objects are likely young, so we can outline the execution after
200
+ // checking hasRememberedSet
201
+ return barrier instanceof SerialWriteBarrierNode serialBarrier && serialBarrier .getBaseStatus ().likelyYoung ();
192
202
}
193
203
194
- private static boolean getVerifyOnly (WriteBarrierNode barrier ) {
195
- if (barrier instanceof SerialWriteBarrierNode ) {
196
- return (( SerialWriteBarrierNode ) barrier ). getVerifyOnly () ;
204
+ private static boolean tryEliminate (WriteBarrierNode barrier ) {
205
+ if (barrier instanceof SerialWriteBarrierNode serialBarrier ) {
206
+ return serialBarrier . isEliminated () || serialBarrier . getBaseStatus () == SerialWriteBarrierNode . BaseStatus . NO_LOOP_OR_SAFEPOINT ;
197
207
}
198
208
return false ;
199
209
}
0 commit comments