changeset 9402:12a66b77145e

8135195: VM Options file should not be limited to 1k in bytes Summary: Change Arguments::parse_vm_options_file() to remove 1024 byte limit on the VM options file. Reviewed-by: dcubed, hseigel, gthornbr, dsamersoff, ddmitriev, coleenp
author dcubed
date Thu, 01 Oct 2015 13:42:42 -0700
parents 59e6f265dd40
children 6020dab5cdcb
files src/share/vm/runtime/arguments.cpp
diffstat 1 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/arguments.cpp	Wed Sep 30 18:09:40 2015 -0400
+++ b/src/share/vm/runtime/arguments.cpp	Thu Oct 01 13:42:42 2015 -0700
@@ -3711,8 +3711,6 @@
   return retcode;
 }
 
-const int OPTION_BUFFER_SIZE = 1024;
-
 jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args) {
   // read file into buffer
   int fd = ::open(file_name, O_RDONLY);
@@ -3723,8 +3721,24 @@
     return JNI_ERR;
   }
 
+  struct stat stbuf;
+  int retcode = os::stat(file_name, &stbuf);
+  if (retcode != 0) {
+    jio_fprintf(defaultStream::error_stream(),
+                "Could not stat options file '%s'\n",
+                file_name);
+    os::close(fd);
+    return JNI_ERR;
+  }
+
+  if (stbuf.st_size == 0) {
+    // tell caller there is no option data and that is ok
+    os::close(fd);
+    return JNI_OK;
+  }
+
   // '+ 1' for NULL termination even with max bytes
-  int bytes_alloc = OPTION_BUFFER_SIZE + 1;
+  size_t bytes_alloc = stbuf.st_size + 1;
 
   char *buf = NEW_C_HEAP_ARRAY_RETURN_NULL(char, bytes_alloc, mtInternal);
   if (NULL == buf) {
@@ -3734,14 +3748,14 @@
     return JNI_ENOMEM;
   }
 
-  memset(buf, 0, (unsigned)bytes_alloc);
+  memset(buf, 0, bytes_alloc);
 
   // Fill buffer
   // Use ::read() instead of os::read because os::read()
   // might do a thread state transition
   // and it is too early for that here
 
-  int bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc);
+  ssize_t bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc);
   os::close(fd);
   if (bytes_read < 0) {
     FREE_C_HEAP_ARRAY(char, buf);
@@ -3756,16 +3770,7 @@
     return JNI_OK;
   }
 
-  // file is larger than OPTION_BUFFER_SIZE
-  if (bytes_read > bytes_alloc - 1) {
-    FREE_C_HEAP_ARRAY(char, buf);
-    jio_fprintf(defaultStream::error_stream(),
-                "Options file '%s' is larger than %d bytes.\n",
-                file_name, bytes_alloc - 1);
-    return JNI_EINVAL;
-  }
-
-  int retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args);
+  retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args);
 
   FREE_C_HEAP_ARRAY(char, buf);
   return retcode;