Add environment flag to control java_max_memory_size in test.py

Change-Id: I320193955c279bf16b60f9c5cb363f75dd25fe77
diff --git a/tools/test.py b/tools/test.py
index 041f17b..9d5e99f 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -118,7 +118,7 @@
       help='Use a custom java version to run tests.')
   result.add_option('--java-max-memory-size', '--java_max_memory_size',
       help='Set memory for running tests, default 4G',
-      default='4G')
+      default=os.environ.get('R8_JAVA_MAX_MEMORY_SIZE', '4G'))
   result.add_option('--test-namespace', '--test_namespace',
       help='Only run tests in  this namespace. The namespace is relative to '
           'com/android/tools/r8, e.g., desugar/desugaredlibrary',