Skip to content

Commit

Permalink
Merge pull request #3198 from gacholio/hash
Browse files Browse the repository at this point in the history
Add option to limit identity hash code to positive values
  • Loading branch information
DanHeidinga committed Oct 10, 2018
2 parents f3607dd + 44faec9 commit 1870fe5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions debugtools/DDR_VM/src/com/ibm/j9ddr/vm29/j9/ObjectHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

import com.ibm.j9ddr.CorruptDataException;
import com.ibm.j9ddr.vm29.pointer.generated.J9BuildFlags;
import com.ibm.j9ddr.vm29.structure.J9Consts;
import com.ibm.j9ddr.vm29.pointer.generated.J9IdentityHashDataPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer;
import com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer;
import com.ibm.j9ddr.vm29.pointer.helper.J9JavaVMHelper;
import com.ibm.j9ddr.vm29.structure.J9IdentityHashData;
import com.ibm.j9ddr.vm29.types.I32;
import com.ibm.j9ddr.vm29.types.U32;
Expand Down Expand Up @@ -134,6 +136,10 @@ private static I32 inlineConvertValueToHash(J9JavaVMPointer vm, UDATA objectPoin
hashValue = hashValue.mult(MUL2);
hashValue = hashValue.bitXor(hashValue.rightShift(16));

/* If forcing positive hash codes, AND out the sign bit */
if (J9JavaVMHelper.extendedRuntimeFlagIsSet(vm, J9Consts.J9_EXTENDED_RUNTIME_POSITIVE_HASHCODE)) {
hashValue = hashValue.bitAnd(0x7FFFFFFF);
}

return new I32(hashValue);
}
Expand Down
7 changes: 6 additions & 1 deletion runtime/oti/ObjectHash.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2017 IBM Corp. and others
* Copyright (c) 1991, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -174,6 +174,11 @@ class VM_ObjectHash
hashValue *= MUL2;
hashValue ^= hashValue >> 16;

/* If forcing positive hash codes, AND out the sign bit */
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_POSITIVE_HASHCODE)) {
hashValue &= (U_32)0x7FFFFFFF;
}

return (I_32) hashValue;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ extern "C" {
#define J9_EXTENDED_RUNTIME_METHOD_TRACE_ENABLED 0x100000
#define J9_EXTENDED_RUNTIME_FOUND_JAVA_ASSERT_OPTION 0x200000
#define J9_EXTENDED_RUNTIME_ALLOW_NON_VIRTUAL_CALLS 0x400000
#define J9_EXTENDED_RUNTIME_UNUSED_0x800000 0x800000
#define J9_EXTENDED_RUNTIME_POSITIVE_HASHCODE 0x800000
#define J9_EXTENDED_RUNTIME_CLASS_OBJECT_ASSIGNED 0x1000000
#define J9_EXTENDED_RUNTIME_FORCE_CLASSFILE_AS_INTERMEDIATE_DATA 0x2000000
#define J9_EXTENDED_RUNTIME_RECREATE_CLASSFILE_ONLOAD 0x4000000
Expand Down
2 changes: 2 additions & 0 deletions runtime/oti/jvminit.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ enum INIT_STAGE {
#define VMOPT_XXDISABLEJITWATCH "-XX:-JITInlineWatches"
#define VMOPT_XXENABLEALWAYSSPLITBYTECODES "-XX:+AlwaysSplitBytecodes"
#define VMOPT_XXDISABLEALWAYSSPLITBYTECODES "-XX:-AlwaysSplitBytecodes"
#define VMOPT_XXENABLEPOSITIVEHASHCODE "-XX:+PositiveIdentityHash"
#define VMOPT_XXDISABLEPOSITIVEHASHCODE "-XX:-PositiveIdentityHash"

#define VMOPT_XX_NOSUBALLOC32BITMEM "-XXnosuballoc32bitmem"

Expand Down
4 changes: 4 additions & 0 deletions runtime/vm/jvminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,10 @@ processVMArgsFromFirstToLast(J9JavaVM * vm)
vm->runtimeFlags |= J9_RUNTIME_ALWAYS_SPLIT_BYTECODES;
} else if (0 == strcmp(testString, VMOPT_XXDISABLEALWAYSSPLITBYTECODES)) {
vm->runtimeFlags &= ~(UDATA)J9_RUNTIME_ALWAYS_SPLIT_BYTECODES;
} else if (0 == strcmp(testString, VMOPT_XXENABLEPOSITIVEHASHCODE)) {
vm->extendedRuntimeFlags |= J9_EXTENDED_RUNTIME_POSITIVE_HASHCODE;
} else if (0 == strcmp(testString, VMOPT_XXDISABLEPOSITIVEHASHCODE)) {
vm->extendedRuntimeFlags &= ~(UDATA)J9_EXTENDED_RUNTIME_POSITIVE_HASHCODE;
}
/* -Xbootclasspath and -Xbootclasspath/p are not supported from Java 9 onwards */
if (J2SE_VERSION(vm) >= J2SE_19) {
Expand Down

0 comments on commit 1870fe5

Please sign in to comment.