47 * Serial warnings are suppressed throughout because all implementation 48 * classes use a serial proxy and thus have no need to declare serialVersionUID. 49 */ 50 @SuppressWarnings("serial") 51 class ImmutableCollections { 52 /** 53 * A "salt" value used for randomizing iteration order. This is initialized once 54 * and stays constant for the lifetime of the JVM. It need not be truly random, but 55 * it needs to vary sufficiently from one run to the next so that iteration order 56 * will vary between JVM runs. 57 */ 58 private static final long SALT32L; 59 60 /** 61 * For set and map iteration, we will iterate in "reverse" stochastically, 62 * decided at bootstrap time. 63 */ 64 private static final boolean REVERSE; 65 static { 66 // to generate a reasonably random and well-mixed SALT, use an arbitrary 67 // value (a slice of pi), multiply with the System.nanoTime, then pick 68 // the mid 32-bits from the product. By picking a SALT value in the 69 // [0 ... 0xFFFF_FFFFL == 2^32-1] range, we ensure that for any positive 70 // int N, (SALT32L * N) >> 32 is a number in the [0 ... N-1] range. This 71 // property will be used to avoid more expensive modulo-based 72 // calculations. 73 long color = 0x243F_6A88_85A3_08D3L; // slice of pi 74 long seed = System.nanoTime(); 75 SALT32L = (int)((color * seed) >> 16) & 0xFFFF_FFFFL; 76 // use the lowest bit to determine if we should reverse iteration 77 REVERSE = (SALT32L & 1) == 0; 78 } 79 80 /** 81 * Constants following this might be initialized from the CDS archive via 82 * this array. 83 */ 84 private static Object[] archivedObjects; 85 86 private static final Object EMPTY; 87 88 static final ListN<?> EMPTY_LIST; 89 90 static final SetN<?> EMPTY_SET; 91 92 static final MapN<?,?> EMPTY_MAP; 93 94 static { | 47 * Serial warnings are suppressed throughout because all implementation 48 * classes use a serial proxy and thus have no need to declare serialVersionUID. 49 */ 50 @SuppressWarnings("serial") 51 class ImmutableCollections { 52 /** 53 * A "salt" value used for randomizing iteration order. This is initialized once 54 * and stays constant for the lifetime of the JVM. It need not be truly random, but 55 * it needs to vary sufficiently from one run to the next so that iteration order 56 * will vary between JVM runs. 57 */ 58 private static final long SALT32L; 59 60 /** 61 * For set and map iteration, we will iterate in "reverse" stochastically, 62 * decided at bootstrap time. 63 */ 64 private static final boolean REVERSE; 65 static { 66 // to generate a reasonably random and well-mixed SALT, use an arbitrary 67 // value (a slice of pi), multiply with a random seed, then pick 68 // the mid 32-bits from the product. By picking a SALT value in the 69 // [0 ... 0xFFFF_FFFFL == 2^32-1] range, we ensure that for any positive 70 // int N, (SALT32L * N) >> 32 is a number in the [0 ... N-1] range. This 71 // property will be used to avoid more expensive modulo-based 72 // calculations. 73 long color = 0x243F_6A88_85A3_08D3L; // slice of pi 74 75 // When running with -Xshare:dump, the VM will supply a "random" seed that's 76 // derived from the JVM build/version, so can we generate the exact same 77 // CDS archive for the same JDK build. This makes it possible to verify the 78 // consistency of the JDK build. 79 long seed = VM.getRandomSeedForCDSDump(); 80 if (seed == 0) { 81 seed = System.nanoTime(); 82 } 83 SALT32L = (int)((color * seed) >> 16) & 0xFFFF_FFFFL; 84 // use the lowest bit to determine if we should reverse iteration 85 REVERSE = (SALT32L & 1) == 0; 86 } 87 88 /** 89 * Constants following this might be initialized from the CDS archive via 90 * this array. 91 */ 92 private static Object[] archivedObjects; 93 94 private static final Object EMPTY; 95 96 static final ListN<?> EMPTY_LIST; 97 98 static final SetN<?> EMPTY_SET; 99 100 static final MapN<?,?> EMPTY_MAP; 101 102 static { |