@@ -3175,7 +3175,7 @@ private Relation checkFunctionOrMethodCompatibility(TypeConstant typeLeft, TypeC
31753175 // the number of returns on the left must not exceed the number of returns on the right;
31763176 // the only exception: "void f(X)" is allowed to be assigned to "Tuple<> f(x)"
31773177 if (cLR > cRR ) {
3178- return cRR == 0 && cLR == 1 && typeLR .getParamType (0 ).equals (currentOr ( this ).typeTuple0 ())
3178+ return cRR == 0 && cLR == 1 && typeLR .getParamType (0 ).equals (getCurrentPool ( ).typeTuple0 ())
31793179 ? Relation .IS_A
31803180 : Relation .INCOMPATIBLE ;
31813181 }
@@ -3433,33 +3433,13 @@ private TypeInfo computeNakedRefInfo(TypeConstant typeReferent) {
34333433 }
34343434
34353435 /**
3436- * The pool to work in: the one bound to this thread if there is one, and the given fallback
3437- * otherwise.
3436+ * Return the working pool associated with the current thread.
34383437 *
3439- * <p>{@link #getCurrentPool} is a thread-local, bound by {@link #withPool} around stretches of
3440- * compilation and by the runtime container. Outside those it is simply null - on a thread
3441- * that is driving the compiler from ordinary Java code, in a test, in a debugger evaluating a
3442- * watch - and code that dereferenced it threw there. Two such NullPointerExceptions were
3443- * found by accident while doing something else, one of them in the code meant to describe a
3444- * structure for a log line.
3438+ * <p>Hosts entering compiler operations that depend on this context must establish a
3439+ * {@link #withPool} scope. A constant's owning pool is not necessarily the working pool:
3440+ * cross-pool operations may intentionally resolve or register constants in another pool.
34453441 *
3446- * <p>The ambient pool is preferred rather than ignored, because it is not always the pool a
3447- * given constant belongs to: {@link #withPool} exists precisely because the compiler works
3448- * across pools, and a well-known constant fetched from the wrong one answers wrongly rather
3449- * than not at all. So this changes nothing where a pool is bound, and answers instead of
3450- * throwing where none is.
3451- *
3452- * @param poolFallback the pool to use when no pool is bound to this thread
3453- *
3454- * @return the pool to work in; null only if the fallback is null
3455- */
3456- public static ConstantPool currentOr (ConstantPool poolFallback ) {
3457- ConstantPool pool = getCurrentPool ();
3458- return pool == null ? poolFallback : pool ;
3459- }
3460-
3461- /**
3462- * @return a ContextPool associated with the current thread
3442+ * @return the working pool, or null if none is associated with this thread
34633443 */
34643444 public static ConstantPool getCurrentPool () {
34653445 return s_tloPool .get ()[0 ];
@@ -3478,6 +3458,10 @@ public static void setCurrentPool(ConstantPool pool) {
34783458 * Temporarily update the current ConstantPool, restoring it when the returned AutoCloseable
34793459 * is closed.
34803460 *
3461+ * <p>Use try-with-resources at the operation boundary, including when inspecting compiler
3462+ * results after compilation. Open and close the scope on the same thread. Work dispatched to
3463+ * another thread must establish its own scope; the context is not inherited.
3464+ *
34813465 * @param pool the new pool
34823466 *
34833467 * @return an Auto which will revert to the prior pool
0 commit comments