public interface SharedClassTokenHelper extends SharedClassHelper
SharedClassHelper API that stores and finds classes using String tokens.
A SharedClassTokenHelper is obtained by calling getTokenHelper(ClassLoader) on a SharedClassHelperFactory.
The SharedClassTokenHelper, which is the most simple type of helper, uses generated String tokens to find and store classes.
The ClassLoader should call findSharedClass after looking in its local cache and asking its parent (if one exists). If findSharedClass does not return null, the ClassLoader calls defineClass on the byte[] that is returned.
The ClassLoader calls storeSharedClass immediately after a class is defined, unless the class that is being defined was loaded from the shared cache.
The ClassLoader is responsible for coordinating the creation of token Strings.
Because the shared cache persists beyond the lifetime of a JVM, classes in the shared cache can become out of date (stale). Using this helper, it is entirely the responsibility of the ClassLoader to ensure that cache entries are kept up-to-date. Tokens have no meaning to the cache, so effectively turn the it into a dictionary of classes.
For example, a token may be the location where the class was found, combined with some type of versioning data.
If a ClassLoader stores multiple versions of the same class by using the same token, only the most recent will be returned by findSharedClass.
A SharedClassHelper will only allow classes to be stored in the cache which were defined by the ClassLoader that owns the SharedClassHelper.
If a SecurityManager is installed, SharedClassPermissions must be used to permit read/write access to the shared class cache. Permissions are granted by ClassLoader classname in the java.policy file and are fixed when the SharedClassHelper is created.
Note also that if the createClassLoader RuntimePermission is not granted, ClassLoaders cannot be created, which in turn means that SharedClassHelpers cannot be created.
Classes stored using the SharedClassTokenHelper cannot be retrieved using any other type of helper, and vice versa.
Modifier and Type | Method and Description |
---|---|
byte[] |
findSharedClass(java.lang.String token,
java.lang.String className)
Finds a class in the shared cache by using a specific token and class name.
|
boolean |
storeSharedClass(java.lang.String token,
java.lang.Class<?> clazz)
Stores a class in the shared cache by using a specific token.
|
getSharingFilter, setSharingFilter
getClassLoader
byte[] findSharedClass(java.lang.String token, java.lang.String className)
A class will be returned only for an exact String match of both the token and class name.
Otherwise, null is returned.
To obtain an instance of the class, the byte[] returned must be passed to defineClass by the caller ClassLoader.
token
- String a token generated by the ClassLoaderclassName
- String the name of the class to be foundboolean storeSharedClass(java.lang.String token, java.lang.Class<?> clazz)
The class that is being stored must have been defined by the caller ClassLoader.
Returns true
if the class is stored successfully or false otherwise.
Will return false
if the class that is being stored was not defined by the caller ClassLoader.
token
- String a token generated by the ClassLoaderclazz
- Class the class to store in the shared cacheEclipse OpenJ9 website.
To raise a bug report or suggest an improvement create an Eclipse OpenJ9 issue.
Copyright © 1998, 2025 IBM Corp. and others.