@@ -133,13 +133,20 @@ private boolean shouldInlineInvoke0(GraphBuilderContext b, SVMHost hostVM, Accum
133133 return true ;
134134 }
135135
136- boolean inMethodHandleIntrinsification = policyScope != null ? policyScope .accumulativeCounters .inMethodHandleIntrinsification : false ;
136+ boolean inMethodHandleIntrinsification = policyScope != null && policyScope .accumulativeCounters .inMethodHandleIntrinsification ;
137137 int allowedInlinings = inMethodHandleIntrinsification ? optionMethodHandleAllowedInlinings : optionAllowedInlinings ;
138138 if (policyScope != null && policyScope .accumulativeCounters .totalInlinedMethods >= allowedInlinings ) {
139139 return false ;
140140 }
141141 int allowedDepth = inMethodHandleIntrinsification ? optionMethodHandleAllowedDepth : optionAllowedDepth ;
142- if (b .getDepth () >= allowedDepth ) {
142+ /*
143+ * Note that we do not use the inlining depth from the GraphBuilderContext: If we are in a
144+ * regular inlining scope, but nested into a deep method handle intrinsification, then the
145+ * total inlining depth is high but our local depth for the scope can still be low enough to
146+ * do inlining.
147+ */
148+ int actualDepth = policyScope == null ? 0 : policyScope .inliningDepth ;
149+ if (actualDepth >= allowedDepth ) {
143150 return false ;
144151 }
145152 if (!inMethodHandleIntrinsification && b .recursiveInliningDepth (method ) > 0 ) {
@@ -284,8 +291,11 @@ public AccumulativeInlineScope createAccumulativeInlineScope(AccumulativeInlineS
284291 * This assumes that the regular limits are strict enough to prevent excessive inlining
285292 * triggered by method handles. We could also use alternative fixed values or the option
286293 * defaults instead of any set option values.
294+ *
295+ * We start again with an inlining depth of 1, i.e., we behave as if that method is the
296+ * inlining root.
287297 */
288- depth = outer . inliningDepth + 1 ;
298+ depth = 1 ;
289299 accumulativeCounters = new AccumulativeCounters (optionAllowedNodes , optionAllowedInvokes , false );
290300
291301 } else {
0 commit comments