@@ -2079,56 +2079,69 @@ int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2079
2079
return JNI_OK;
2080
2080
}
2081
2081
2082
+ // Temporary system property to disable preview patching and enable the new preview mode
2083
+ // feature for testing/development. Once the preview mode feature is finished, the value
2084
+ // will be always 'true' and this code, and all related dead-code can be removed.
2085
+ #define DISABLE_PREVIEW_PATCHING_DEFAULT false
2086
+
2087
+ bool Arguments::disable_preview_patching () {
2088
+ const char * prop = get_property (" DISABLE_PREVIEW_PATCHING" );
2089
+ return (prop != nullptr )
2090
+ ? strncmp (prop, " true" , strlen (" true" )) == 0
2091
+ : DISABLE_PREVIEW_PATCHING_DEFAULT;
2092
+ }
2093
+
2082
2094
// VALUECLASS_STR must match string used in the build
2083
2095
#define VALUECLASS_STR " valueclasses"
2084
2096
#define VALUECLASS_JAR " -" VALUECLASS_STR " .jar"
2085
2097
2086
2098
// Finalize --patch-module args and --enable-preview related to value class module patches.
2087
2099
// Create all numbered properties passing module patches.
2088
2100
int Arguments::finalize_patch_module () {
2089
- // If --enable-preview and EnableValhalla is true, each module may have value classes that
2090
- // are to be patched into the module.
2101
+ // If --enable-preview and EnableValhalla is true, modules may have preview mode resources.
2091
2102
bool enable_valhalla_preview = enable_preview () && EnableValhalla;
2103
+ // Whether to use module patching, or the new preview mode feature for preview resources.
2104
+ bool disable_patching = disable_preview_patching ();
2092
2105
2093
2106
// This must be called, even with 'false', to enable resource lookup from JImage.
2094
- ClassLoader::init_jimage (enable_valhalla_preview);
2107
+ ClassLoader::init_jimage (disable_patching && enable_valhalla_preview);
2108
+
2109
+ // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2110
+ // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2111
+ if (!disable_patching && enable_valhalla_preview) {
2112
+ char * valueclasses_dir = AllocateHeap (JVM_MAXPATHLEN, mtArguments);
2113
+ const char * fileSep = os::file_separator ();
2114
+
2115
+ jio_snprintf (valueclasses_dir, JVM_MAXPATHLEN, " %s%slib%s" VALUECLASS_STR " %s" ,
2116
+ Arguments::get_java_home (), fileSep, fileSep, fileSep);
2117
+ DIR* dir = os::opendir (valueclasses_dir);
2118
+ if (dir != nullptr ) {
2119
+ char * module_name = AllocateHeap (JVM_MAXPATHLEN, mtArguments);
2120
+ char * path = AllocateHeap (JVM_MAXPATHLEN, mtArguments);
2121
+
2122
+ for (dirent * entry = os::readdir (dir); entry != nullptr ; entry = os::readdir (dir)) {
2123
+ // Test if file ends-with "-valueclasses.jar"
2124
+ int len = (int )strlen (entry->d_name ) - (sizeof (VALUECLASS_JAR) - 1 );
2125
+ if (len <= 0 || strcmp (&entry->d_name [len], VALUECLASS_JAR) != 0 ) {
2126
+ continue ; // too short or not the expected suffix
2127
+ }
2095
2128
2096
- // // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2097
- // // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2098
- // if (enable_valhalla_preview) {
2099
- // char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2100
- // const char * fileSep = os::file_separator();
2101
- //
2102
- // jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2103
- // Arguments::get_java_home(), fileSep, fileSep, fileSep);
2104
- // DIR* dir = os::opendir(valueclasses_dir);
2105
- // if (dir != nullptr) {
2106
- // char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2107
- // char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2108
- //
2109
- // for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2110
- // // Test if file ends-with "-valueclasses.jar"
2111
- // int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2112
- // if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2113
- // continue; // too short or not the expected suffix
2114
- // }
2115
- //
2116
- // strcpy(module_name, entry->d_name);
2117
- // module_name[len] = '\0'; // truncate to just module-name
2118
- //
2119
- // jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2120
- // add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2121
- // log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2122
- // }
2123
- // FreeHeap(module_name);
2124
- // FreeHeap(path);
2125
- // os::closedir(dir);
2126
- // }
2127
- // FreeHeap(valueclasses_dir);
2128
- // }
2129
+ strcpy (module_name, entry->d_name );
2130
+ module_name[len] = ' \0 ' ; // truncate to just module-name
2131
+
2132
+ jio_snprintf (path, JVM_MAXPATHLEN, " %s%s" , valueclasses_dir, &entry->d_name );
2133
+ add_patch_mod_prefix (module_name, path, true /* append */ , true /* cds OK*/ );
2134
+ log_info (class )(" --enable-preview appending value classes for module %s: %s" , module_name, entry->d_name );
2135
+ }
2136
+ FreeHeap (module_name);
2137
+ FreeHeap (path);
2138
+ os::closedir (dir);
2139
+ }
2140
+ FreeHeap (valueclasses_dir);
2141
+ }
2129
2142
2130
2143
// Create numbered properties for each module that has been patched either
2131
- // by --patch-module or --enable-preview
2144
+ // by --patch-module ( or --enable-preview if disable_patching is false).
2132
2145
// Format is "jdk.module.patch.<n>=<module_name>=<path>"
2133
2146
if (_patch_mod_prefix != nullptr ) {
2134
2147
char * prop_value = AllocateHeap (JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1 , mtArguments);
0 commit comments