Skip to content

Commit 588209f

Browse files
committed
Add documentation to PythonObjectFactory
1 parent 0564462 commit 588209f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.net.ssl.SSLEngine;
3535

3636
import com.oracle.graal.python.PythonLanguage;
37+
import com.oracle.graal.python.builtins.Python3Core;
3738
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3839
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.PosixFileHandle;
3940
import com.oracle.graal.python.builtins.modules.bz2.BZ2Object;
@@ -197,6 +198,26 @@
197198
import com.oracle.truffle.api.object.HiddenKey;
198199
import com.oracle.truffle.api.object.Shape;
199200

201+
/**
202+
* Factory for Python objects that also reports to Truffle's {@link AllocationReporter}. The
203+
* reporting needs current context. There are several implementations of this abstract class. Use
204+
* this rule of thumb when choosing which one to use:
205+
* <ul>
206+
* <li>In partially evaluated code: use adopted (@Child/@Cached) {@link PythonObjectFactory} node
207+
* </li>
208+
* <li>Behind {@code TruffleBoundary}:
209+
* <ul>
210+
* <li>When the current context is already available, use {@link Python3Core#factory()}. This avoids
211+
* repeated context lookups inside the factory.</li>
212+
* <li>When the current context is not available, but multiple objects will be created: lookup the
213+
* context and use {@link Python3Core#factory()}. This executes only one context lookup. Note: first
214+
* check if the caller could pass the context to avoid looking it up behind {@code TruffleBoundary}.</li>
215+
* <li>When the current context is not available, and only one object is to be created: use
216+
* {@link PythonObjectFactory#getUncached()}.</li>
217+
* </ul>
218+
* </li>
219+
* </ul>
220+
*/
200221
@GenerateUncached
201222
@ImportStatic(PythonOptions.class)
202223
public abstract class PythonObjectFactory extends Node {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectSlowPathFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
* explicitly available.
5757
*
5858
* Objects of this class should not be created directly, but retrieved from
59-
* {@link com.oracle.graal.python.builtins.Python3Core}.
59+
* {@link com.oracle.graal.python.builtins.Python3Core}. Note that
60+
* {@link PythonObjectSlowPathFactory} is context dependent object. It must not be stored in AST or
61+
* in {@link com.oracle.graal.python.PythonLanguage}, for example.
6062
*/
6163
public final class PythonObjectSlowPathFactory extends PythonObjectFactory {
6264

0 commit comments

Comments
 (0)