/** Enters a stack context instance (private since instances are not configurable). */ private static StackContext enter() { StackContext ctx = AbstractContext.current(StackContext.class); if (ctx == null) { ctx = STACK_CONTEXT_TRACKER.getService(WAIT_FOR_SERVICE.get(), DEFAULT); } return (StackContext) ctx.enterInner(); }
/** * Executes the specified function allocating objects on the stack; the function result is copied * to calling context. */ public static <P, R extends Copyable<R>> R execute(Function<P, R> function, P parameter) { StackContext ctx = StackContext.enter(); try { return ctx.executeInContext(function, parameter); } finally { ctx.exit(); } }
/** Executes the specified logic allocating objects on the stack. */ public static void execute(Runnable logic) { StackContext ctx = StackContext.enter(); try { ctx.executeInContext(logic); } finally { ctx.exit(); } }