LoginSignup
1
0

JavaのReservedCodeCacheSizeの最大値

Posted at

はじめに

Javaのコードキャッシュサイズは起動オプション -XX:ReservedCodeCacheSize で指定できる。
これの最大値は以下のドキュメントでは 2GB とある。
https://docs.oracle.com/javase/jp/8/docs/technotes/tools/unix/java.html

この値はマシンスペックや他のオプションによる影響を受けないのかソースコードで調べてみた。
結論から言うと 2GB 固定である。
以下の実機確認、ソースコードはJava11のもの。

実機確認

2GB(2048MB) を超えるとエラーになることがわかる。

lemon >> java -XX:ReservedCodeCacheSize=2048m hello
Hello, world.
lemon >> java -XX:ReservedCodeCacheSize=2049m hello
Invalid ReservedCodeCacheSize=2049M. Must be at most 2048M.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

ソースコード

実機確認で出たメッセージから検索してみると以下で出していることがわかる。

share/compiler/compilerDefinitions.cpp
bool CompilerConfig::check_args_consistency(bool status) {
  // Check lower bounds of the code cache
  // Template Interpreter code is approximately 3X larger in debug builds.
  uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
.....
  } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
    // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
    jio_fprintf(defaultStream::error_stream(),
                "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
                CODE_CACHE_SIZE_LIMIT/M);
    status = false;

ReservedCodeCacheSize が CODE_CACHE_SIZE_LIMIT より大きい場合に本メッセージを出している。
CODE_CACHE_SIZE_LIMIT は以下で定義されている。

share/utilities/globalDefinitions.hpp
// The maximum size of the code cache.  Can be overridden by targets.
#define CODE_CACHE_SIZE_LIMIT (2*G)

2Gで決め打ちされているのでマシンスペックや他のオプションによる影響を受けないことがわかる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0