Skip to content

Commit ae4e835

Browse files
committed
Update FastThreadLocal documentation.
1 parent 5b3ee38 commit ae4e835

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/threadlocal/FastThreadLocalFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
import org.graalvm.word.WordBase;
3434

3535
/**
36-
* This class contains factory methods to create fast thread local variables. A thread local
36+
* This class contains factory methods to create {@link FastThreadLocal} variables. A thread local
3737
* variable is represented as an object, with different classes for primitive {@code int} (class
3838
* {@link FastThreadLocalInt}), primitive {@code long} (class {@link FastThreadLocalLong}),
3939
* {@link Object} (class {@link FastThreadLocalObject}), and {@link WordBase word} (class
4040
* {@link FastThreadLocalWord}) values. Access to such thread local variables is significantly
41-
* faster than regular Java {@link ThreadLocal} variables. However, there are several restrictions:
41+
* faster than regular Java {@link ThreadLocal} variables. This is achieved by determining all the
42+
* {@link FastThreadLocal} values and their size at build time and reserving space in the
43+
* {@link IsolateThread} data structure. However, there are several restrictions:
4244
* <ul>
4345
* <li>The thread local object must be created during native image generation. Otherwise, the size
4446
* of the {@link IsolateThread} data structure would not be a compile time constant.</li>
@@ -63,6 +65,9 @@
6365
* The implementation of fast thread local variables and the way the data is stored is
6466
* implementation specific and transparent for users of it. However, the access is fast and never
6567
* requires object allocation.
68+
* <p>
69+
* See also {@link VMThreadLocalInfo} for additional information about how a {@link FastThreadLocal}
70+
* is handled during build time.
6671
*/
6772
@Platforms(Platform.HOSTED_ONLY.class)
6873
public final class FastThreadLocalFactory {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/threadlocal/VMThreadLocalInfo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828

2929
import java.util.function.IntSupplier;
3030

31+
import org.graalvm.nativeimage.IsolateThread;
3132
import org.graalvm.nativeimage.Platform;
3233
import org.graalvm.nativeimage.Platforms;
3334
import org.graalvm.word.LocationIdentity;
3435
import org.graalvm.word.WordBase;
3536

3637
import com.oracle.svm.core.BuildPhaseProvider.ReadyForCompilation;
3738
import com.oracle.svm.core.config.ConfigurationValues;
39+
import com.oracle.svm.core.graal.thread.LoadVMThreadLocalNode;
40+
import com.oracle.svm.core.graal.thread.StoreVMThreadLocalNode;
3841
import com.oracle.svm.core.heap.UnknownPrimitiveField;
3942

4043
import jdk.vm.ci.meta.JavaKind;
@@ -74,7 +77,18 @@ public static Class<?> getValueClass(Class<? extends FastThreadLocal> threadLoca
7477
public final boolean allowFloatingReads;
7578
public final String name;
7679

80+
/**
81+
* Offset of this thread local variable from its holder thread {@link IsolateThread} data
82+
* structure. It is a compile time constant, determined by collecting and sorting all thread
83+
* locals, and used during lowering of {@link FastThreadLocal} specific operations, e.g.,
84+
* {@link LoadVMThreadLocalNode}, {@link StoreVMThreadLocalNode} and others.
85+
*/
7786
@UnknownPrimitiveField(availability = ReadyForCompilation.class) public int offset;
87+
/**
88+
* How many bytes does this thread local need for storage. Just like the {@link #offset} this is
89+
* a compile-time constant, determined by taking into account the {@link #storageKind} or via
90+
* the {@link #sizeSupplier}, and it is used to lay out the thread locals in memory.
91+
*/
7892
@UnknownPrimitiveField(availability = ReadyForCompilation.class) public int sizeInBytes;
7993

8094
@Platforms(Platform.HOSTED_ONLY.class)

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/thread/VMThreadFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void duringSetup(DuringSetupAccess config) {
103103
* <p>
104104
* When the {@link IsolateThread} is not passed in as a parameter, we use the
105105
* {@link LoadVMThreadLocalNode current thread}. We do not need read/write barriers since we
106-
* access memory that we manage ourselfs.
106+
* access memory that we manage ourselves.
107107
*/
108108
@Override
109109
public void registerInvocationPlugins(Providers providers, Plugins plugins, ParsingReason reason) {

0 commit comments

Comments
 (0)