-
Bug
-
Resolution: Fixed
-
P4
-
5.0, 6
-
b17
-
generic, x86
-
generic, linux, windows_xp
Bill Pugh writes:
We've been working on tuning the dead store detector, and came across
this
in java.util.UUID:
/**
* Static factory to retrieve a type 4 (pseudo randomly generated)
UUID.
*
* The <code>UUID</code> is generated using a cryptographically
strong
* pseudo random number generator.
*
* @return a randomly generated <tt>UUID</tt>.
*/
public static UUID randomUUID() {
SecureRandom ng = numberGenerator;
if (ng == null) {
numberGenerator = ng = new SecureRandom();
}
byte[] randomBytes = new byte[16];
ng.nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= 0x80; /* set to IETF variant */
UUID result = new UUID(randomBytes);
return new UUID(randomBytes);
}
Result of this is that for each call, you create two UUID objects, one
of which is thrown away.
Only a performance penalty, rather than correctness. But still, it
should be fixed.
Bill
We've been working on tuning the dead store detector, and came across
this
in java.util.UUID:
/**
* Static factory to retrieve a type 4 (pseudo randomly generated)
UUID.
*
* The <code>UUID</code> is generated using a cryptographically
strong
* pseudo random number generator.
*
* @return a randomly generated <tt>UUID</tt>.
*/
public static UUID randomUUID() {
SecureRandom ng = numberGenerator;
if (ng == null) {
numberGenerator = ng = new SecureRandom();
}
byte[] randomBytes = new byte[16];
ng.nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= 0x80; /* set to IETF variant */
UUID result = new UUID(randomBytes);
return new UUID(randomBytes);
}
Result of this is that for each call, you create two UUID objects, one
of which is thrown away.
Only a performance penalty, rather than correctness. But still, it
should be fixed.
Bill
- duplicates
-
JDK-6179537 UUID.randomUUID() makes an unnecessary call to the UUID constructor
-
- Closed
-