Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-03-13 backports 17 sync #697

Merged
merged 126 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
75ab50b
respect maximum eden size in AggressiveShrinkCollectionPolicy.
mur47x111 Jul 27, 2023
8b3a051
Improve OutOfMemoryError messages.
christianhaeubl Oct 16, 2023
2532d19
Fixes issue-7652 for epsilon gc
Karm Oct 26, 2023
c8fb366
Remove broken method VMError.shouldNotReachHereAtRuntime().
christianhaeubl Dec 6, 2023
2cb5ba3
[GR-50383] Backport to 23.0: HeapImpl.dirtyAllReferencesOf must be no…
medoussboug Dec 10, 2023
634e1d7
update to jvmci-23.0-b26
OracleLabsAutomation Dec 12, 2023
e0faae4
Backport to 23.0: Improve OutOfMemoryError messages.
ossama-ismaili Dec 12, 2023
0e80671
[GR-50820] Update JVMCI to jvmci-23.0-b26
OracleLabsAutomation Dec 13, 2023
9c24b11
[GR-50952] Backport to 23.0 : Respect maximum eden size in Aggressive…
mur47x111 Dec 15, 2023
394f15d
Fix intrinsic frame states
gergo- Dec 18, 2023
a79ef82
[GR-49481] Remove explicit null check exceptions from genCheckCast an…
rmosaner Dec 18, 2023
247b7a9
update to jvmci-23.0-b27
OracleLabsAutomation Dec 20, 2023
81011a5
[GR-49481] Backport to 23.0: Remove explicit null check exceptions fr…
rmosaner Dec 21, 2023
cc48ed3
[GR-51030] Update JVMCI to jvmci-23.0-b27
OracleLabsAutomation Dec 21, 2023
25e5416
Speedup method verification.
teshull Jun 20, 2023
6e2ed2c
GR-50540 : release GraalVM 23.0.3
marwan-hallaoui Dec 29, 2023
ad9a4ab
Remove Heap.allowPageSizeMismatch().
christianhaeubl Dec 19, 2023
e7efdb3
Provide a method to set the physical memory size.
christianhaeubl Jan 5, 2024
0bf3cb9
New dev cycle GraalVM 23.0.4
elkorchi Jan 12, 2024
29d8bf0
Use unsigned monitor and identity hash offsets and guarantee (not ass…
peter-hofer Nov 9, 2023
4b5165b
[GR-48705] Fix stamp inversion for ZeroExtend and SignExtend operations.
rmosaner Sep 27, 2023
5bcae4c
[GR-48705] Unittests for stamp inversion during conditional elimination.
rmosaner Oct 3, 2023
6acb9d0
[GR-48705] Infer input msb during stamp inversion for integer SignExt…
rmosaner Oct 3, 2023
c45cbb0
Fix Cpuid1Ecx feature parsing for AMD CPUs.
fniephaus Jan 15, 2024
6844df7
fix debug section alignment which can lead to corrupt debug info
esytnik Dec 18, 2023
3c86fd2
Add crash log output to exception handling.
christianhaeubl Dec 15, 2023
7adafba
Catch exceptions that happen while a thread starts.
christianhaeubl Dec 15, 2023
382fbd4
Only use -H:Path validation in non-bundle mode
olpaw Jan 15, 2024
46bd365
Explain reasoning as comment
olpaw Jan 15, 2024
9dfadcc
update to jvmci-23.0-b28
OracleLabsAutomation Jan 17, 2024
6434a52
[GR-51332] Update JVMCI to jvmci-23.0-b28
OracleLabsAutomation Jan 19, 2024
3171106
[GR-48705] Incorporate the bounds of stampToInvert when calculating t…
rmosaner Oct 10, 2023
a0af55d
[GR-50965] Backport to 23.0: Print crash log when exception handling …
elkorchi Jan 22, 2024
1c5f7df
Fix a bug in the IsolateArgumentParser.
christianhaeubl Jan 19, 2024
eefa873
update to jvmci-23.0-b29
OracleLabsAutomation Jan 23, 2024
dafc7ac
Fix Thread.getStackTrace() right after Thread.start().
peter-hofer Oct 13, 2023
979fdc8
[GR-51378] Backport to 23.0: Fix Cpuid1Ecx feature parsing for AMD CPUs.
medoussboug Jan 23, 2024
30172fa
[GR-50823] Fix stamp inversion for ZeroExtend and SignExtend operations.
rmosaner Sep 27, 2023
5bc925f
[GR-50823] Unittests for stamp inversion during conditional elimination.
rmosaner Oct 3, 2023
9dc5184
[GR-50823] Infer input msb during stamp inversion for integer SignExt…
rmosaner Oct 3, 2023
d27644e
[GR-50823] Incorporate the bounds of stampToInvert when calculating t…
rmosaner Oct 10, 2023
3ec89db
Preprocess `_MSC_FULL_VER` to detect `cl.exe` version info.
fniephaus Dec 18, 2023
0d15e38
Drop redundant architecture error for Windows.
fniephaus Dec 20, 2023
fa26b2f
Mark `skipLineIfHasNext` as static.
fniephaus Jan 24, 2024
68e2bf5
[GR-51092] Backport to 23.0: Fix debug section alignment which can le…
medoussboug Jan 24, 2024
3029285
Add memory barrier to HeapImpl.getAllClasses().
christianhaeubl Jan 12, 2024
e4960ed
Crash log improvements.
christianhaeubl Jan 12, 2024
db7598b
[GR-51426] Backport to 23.0: Only use -H:Path validation in non-bundl…
kassifar Jan 25, 2024
9628a66
Minor fixes and cleanups.
christianhaeubl Dec 6, 2023
789515b
[GR-51095] Speedup method verification.
teshull Jan 25, 2024
c51f725
[GR-50823] Backport to 23.0: Fix stamp inversion for ZeroExtend and S…
aelmassa Jan 25, 2024
298e76d
Adapt fix to 23.0
hamzaGhaissi Jan 25, 2024
641d834
Correctly print JSON values in agent trace files.
peter-hofer Oct 24, 2023
d5be7d2
Support access-filter-file for native-image-configure.
peter-hofer Oct 24, 2023
8cd0f84
[GR-51482] Update JVMCI to jvmci-23.0-b29
OracleLabsAutomation Jan 27, 2024
eea71aa
[GR-51089] Backport to 23.0: Preprocess `_MSC_FULL_VER` to detect `cl…
selhagani Jan 27, 2024
8670a41
update to jvmci-23.0-b30
OracleLabsAutomation Jan 28, 2024
00fafdd
[GR-51484] Backport to 23.0: Fix a bug in the IsolateArgumentParser.
selhagani Jan 28, 2024
439c54d
[GR-50824] Backport to 23.0.3 : Fix stamp inversion for ZeroExtend an…
TheTaha-Alamine Jan 28, 2024
c5c226d
Fix identity hash offset assertion
marwan-hallaoui Jan 29, 2024
d07148b
fix style issue
marwan-hallaoui Jan 29, 2024
331a408
update VSCode version
elkorchi Jan 29, 2024
4a3680c
[GR-51631] Update JVMCI to jvmci-23.0-b30
OracleLabsAutomation Jan 29, 2024
e29c3b2
[GR-50915] Backport to 23.0: Fix Thread.getStackTrace() right after T…
hamzaGhaissi Jan 30, 2024
1e2c50b
[GR-51176] [GR-51183] Remove Heap.allowPageSizeMismatch() and provide…
christianhaeubl Jan 30, 2024
1a79e3c
[GR-51312] Backport to 23.0: Crash log improvements.
christianhaeubl Jan 30, 2024
ead2eaa
[GR-50803] Backport to 23.0: Minor fixes and cleanups.
medoussboug Jan 31, 2024
a56e934
[GR-50880] Backport to 23.0: Correctly handle printing certain JSON v…
elkorchi Jan 31, 2024
cf89f68
induction variables: only non overflowing constant properties should be
davleopo Jan 19, 2024
a892411
Use a common ThreadStartRoutinePrologue on all platforms.
christianhaeubl Jan 30, 2024
7000a5b
Fix a Windows-specific thread handle leak.
christianhaeubl Jan 18, 2024
cada29f
Adapt fix to 23.0
hamzaGhaissi Jan 31, 2024
6bc5e3b
Avoid deadlocks when the VM is out-of-memory and other threading-rela…
christianhaeubl Jan 8, 2024
49971dd
Add checks for recently started threads without Thread object.
peter-hofer Jan 25, 2024
76378a5
Substitute synchronized NullPointerException.fillInStackTrace which i…
peter-hofer Jan 25, 2024
89b4ccf
[GR-51798] Backport to 23.0: Handle recently started threads without …
peter-hofer Feb 1, 2024
c464963
[GR-51583] Backport to 23.0: induction variables: only non overflowin…
hamzaGhaissi Feb 5, 2024
23f2e5f
[GR-51690] [GR-51517] Backport to 23.0: Avoid deadlocks when the VM i…
christianhaeubl Feb 5, 2024
c2f7326
guard against deleting canonicalizer replacement.
teshull Feb 2, 2024
203e6f0
regression test
dougxc Feb 2, 2024
c8695a8
Adapt fix to 23.0
hamzaGhaissi Feb 6, 2024
f23928a
[GR-51110] Could not load library @rpath/libjsig.dylib for nodejs nat…
woess Feb 7, 2024
8e91e9e
Don't try to incorrectly move virtual state inputs out of loops
gergo- Sep 15, 2023
744425b
graph order: run some form of schedule verification in all tiers if
davleopo Aug 11, 2023
93d21e0
Properly catch exceptions during shutdown.
christianhaeubl Feb 1, 2024
48c5102
[GR-51824] Backport to 23.0: Guard against deleting canonicalizer rep…
hamzaGhaissi Feb 8, 2024
f4a6c8f
[GR-51830] Backport to 23.0: Cleanups and minor fixes.
selhagani Feb 9, 2024
60f34f8
Constant fold reflection lookups in sun.nio.ch.Reflect
Dec 15, 2023
a26dc5c
Fix MacOS-specific perf data issue.
christianhaeubl Feb 9, 2024
212b26f
[GR-50879] Backport 23.0 : Use unsigned monitor and identity hash off…
marwan-hallaoui Feb 9, 2024
7447a13
[GR-51029] Backport to 23.0: Constant fold reflection lookups in sun.…
elkorchi Feb 9, 2024
43d6c00
Fix a deadlock in IsolateAwareTruffleCompiler.tearDownIsolateOnShutdown.
christianhaeubl Feb 7, 2024
f4a2f60
[GR-51592][GR-51892] Backport to 23.0: Don't try to incorrectly move …
kassifar Feb 12, 2024
7753d83
Remove GU catalogs for CE
elkorchi Feb 12, 2024
bd4f832
ensure CompilationResult.methods does not contain duplicates
dougxc Feb 5, 2024
90e384d
[GR-51958] Backport to: 20.3 Fix a deadlock in IsolateAwareTruffleCom…
selhagani Feb 14, 2024
54b29bf
Workaround for a build-time crash.
christianhaeubl Feb 8, 2024
7f5d135
[GR-51927] Backport to 23.0: Ensure CompilationResult.methods does no…
hamzaGhaissi Feb 16, 2024
63810f1
[GR-52064] Backport to 23.0: Workaround for a build-time crash.
selhagani Feb 16, 2024
45b881b
update to jvmci-23.0-b31
OracleLabsAutomation Feb 16, 2024
1b0ea0d
Don't optimize away Narrow in comparisons with mixed signedness
gergo- Feb 2, 2024
241e8f5
[WIP] Update JVMCI to jvmci-23.0-b31
OracleLabsAutomation Feb 19, 2024
5eac86a
[GR-51834] Remove GU catalogs for CE
elkorchi Feb 19, 2024
a726caa
[GR-52106] Backport to 23.0: Don't optimize away Narrow in comparison…
hamzaGhaissi Feb 21, 2024
fcac25c
[GR-50834] Fix intrinsic frame states
gergo- Feb 22, 2024
1eb5b4e
[GR-51970] Backport to 23.0: Fix MacOS-specific perf data issue.
medoussboug Feb 22, 2024
c3babdb
update to jvmci-23.0-b32
OracleLabsAutomation Feb 22, 2024
056e1fe
Allow TRegex to be used in SandboxPolicy.UNTRUSTED.
woess Jul 10, 2023
94a1ab6
[GR-52245] Update JVMCI to jvmci-23.0-b32
OracleLabsAutomation Feb 23, 2024
fdde766
loop fragment: ensure we are not killing control flow when we have
davleopo Feb 19, 2024
dc38fbd
[GR-52290] Backport to 23.0: Regex language connot be used with UNTRU…
tzezula Feb 26, 2024
82a01f9
Workarounds for wrong class initialization configuration in microserv…
Jul 12, 2023
801442b
fixed read nodes must only be removed if they are not used as null
davleopo Feb 5, 2024
c868c71
Make segfault handler more robust.
christianhaeubl Dec 7, 2023
c365a6f
[GR-52226] Backport to 23.0: Loop fragment: ensure we are not killing…
medoussboug Feb 27, 2024
1b76fac
Adapt fix
kassifar Feb 28, 2024
ea3e3c8
Improve uncaught exception handler and error handling in CEntryPointS…
christianhaeubl Feb 12, 2024
4d321e6
Add option ImplicitExceptionWithoutStacktraceIsFatal.
christianhaeubl Feb 5, 2024
a37e926
[GR-52343] [GR-51754] Fixes for new class initialization strategy.
elkorchi Feb 29, 2024
caa5a64
[GR-50972] Backport to 23.0: Make segfault handler more robust.
christianhaeubl Feb 29, 2024
d5c9566
[GR-51870] Backport to 23.0: Fixed read nodes must only be removed if…
kassifar Feb 29, 2024
ca1ea97
[GR-52326] Backport to 23.0: Deopt loops in NetSuite JS code.
woess Feb 29, 2024
f01c553
update to jvmci-23.0-b33
OracleLabsAutomation Feb 29, 2024
3016b3d
[GR-52399] Update JVMCI to jvmci-23.0-b33
OracleLabsAutomation Mar 1, 2024
9693aa5
[GR-52020] Backport to 23.0: Improve uncaught exception handler and e…
christianhaeubl Mar 5, 2024
4ec27e3
Merge upstream graalvm-for-jdk17-community-backports master branch
zakkak Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/common.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local common_json = import "../common.json";

# The devkits versions reflect those used to build the JVMCI JDKs (e.g., see devkit_platform_revisions in <jdk>/make/conf/jib-profiles.js)
devkits: {
"windows-jdk17": { packages+: { "devkit:VS2022-17.1.0+1": "==0" }},
"windows-jdk17": { packages+: { "devkit:VS2022-17.6.5+1": "==0" }},
"windows-jdk19": { packages+: { "devkit:VS2022-17.1.0+1": "==0" }},
"windows-jdk20": { packages+: { "devkit:VS2022-17.1.0+1": "==0" }},
"linux-jdk17": { packages+: { "devkit:gcc10.3.0-OL6.4+1": "==0" }},
Expand Down
6 changes: 3 additions & 3 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.9+9-jvmci-23.0-b22", "platformspecific": true },
"labsjdk-ce-17Debug": {"name": "labsjdk", "version": "ce-17.0.9+9-jvmci-23.0-b22-debug", "platformspecific": true },
"labsjdk-ce-17-llvm": {"name": "labsjdk", "version": "ce-17.0.9+9-jvmci-23.0-b22-sulong", "platformspecific": true },
"labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.10+9-jvmci-23.0-b25", "platformspecific": true },
"labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.10+9-jvmci-23.0-b25-debug", "platformspecific": true },
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.10+9-jvmci-23.0-b25-sulong", "platformspecific": true },
"labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.11+6-jvmci-23.0-b33", "platformspecific": true },
"labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.11+6-jvmci-23.0-b33-debug", "platformspecific": true },
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.11+6-jvmci-23.0-b33-sulong", "platformspecific": true },

"oraclejdk19": {"name": "jpg-jdk", "version": "19", "build_id": "26", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-19": {"name": "labsjdk", "version": "ce-19.0.1+10-jvmci-23.0-b04", "platformspecific": true },
Expand Down
2 changes: 1 addition & 1 deletion compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceinprojectwhitelist" : [],

"groupId" : "org.graalvm.compiler",
"version" : "23.0.3.1",
"version" : "23.0.4.0",
"release" : False,
"url" : "http://www.graalvm.org/",
"developer" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public String toString() {
private Assumption[] assumptions;

/**
* The list of the methods whose bytecodes were used as input to the compilation. If
* The set of the methods whose bytecodes were used as input to the compilation. If
* {@code null}, then the compilation did not record method dependencies. Otherwise, the first
* element of this array is the root method of the compilation.
*/
Expand Down Expand Up @@ -361,45 +361,36 @@ public Assumption[] getAssumptions() {
}

/**
* Sets the methods whose bytecodes were used as input to the compilation.
* Records the set of methods whose bytecodes were used as input to the compilation.
*
* @param rootMethod the root method of the compilation
* @param inlinedMethods the methods inlined during compilation
* @param inlinedMethods the methods inlined during compilation (may contain duplicates)
*/
public void setMethods(ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods) {
checkOpen();
assert rootMethod != null;
assert inlinedMethods != null;
if (inlinedMethods.contains(rootMethod)) {
methods = inlinedMethods.toArray(new ResolvedJavaMethod[inlinedMethods.size()]);
for (int i = 0; i < methods.length; i++) {
if (methods[i].equals(rootMethod)) {
if (i != 0) {
ResolvedJavaMethod tmp = methods[0];
methods[0] = methods[i];
methods[i] = tmp;
}
break;
}
}
} else {
methods = new ResolvedJavaMethod[1 + inlinedMethods.size()];
methods[0] = rootMethod;
int i = 1;
for (ResolvedJavaMethod m : inlinedMethods) {
methods[i++] = m;
}

EconomicSet<ResolvedJavaMethod> methodSet = EconomicSet.create(inlinedMethods.size());
methodSet.addAll(inlinedMethods);
methodSet.remove(rootMethod);
methods = new ResolvedJavaMethod[1 + methodSet.size()];
methods[0] = rootMethod;
int i = 1;
for (ResolvedJavaMethod m : methodSet) {
methods[i++] = m;
}
}

/**
* Gets the methods whose bytecodes were used as input to the compilation.
* Gets the set of methods whose bytecodes were used as input to the compilation.
*
* The caller must not modify the contents of the returned array.
*
* @return {@code null} if the compilation did not record method dependencies otherwise the
* methods whose bytecodes were used as input to the compilation with the first element
* being the root method of the compilation
* being the root method of the compilation. The entries in a non-null returned array
* are guaranteed to be unique.
*/
public ResolvedJavaMethod[] getMethods() {
return methods;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,16 @@ public IntegerConvertOp<T> unwrap() {
}

/**
* Computes the stamp of the input for the given output stamp.
* Computes the stamp of the input for the given output stamp. This method returns
* {@code null} if a stamp cannot be inverted for an operation (i.e., {@link Narrow}). When
* inverting non-exact stamps, i.e. {@code 0xx0xxxx}, the inversion keeps all available
* information. If the stamp to invert contains contradictions regarding the post condition
* of the operation, an empty stamp is returned. An example for a contradiction would be a
* {@code SignExtend} with both {@code 0} and {@code 1} in the extension.
*
* @return {@code null} - if stamp inversion is not supported </br>
* empty stamp - if the output stamp contains contradictions </br>
* inverted output stamp - otherwise </br>
*/
public abstract Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1976,24 +1976,31 @@ public Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp) {
}

/*
* there is no guarantee that a given result is in the range of the
* There is no guarantee that a given result is in the range of the
* input because of holes in ranges resulting from signed / unsigned
* extension, so we must ensure that the extension bits are all zeros
* otherwise we cannot represent the result, and we have to return an
* unrestricted stamp
* empty stamp.
*
* This case is much less likely to happen than the case for SignExtend
* but the following is defensive to ensure that we only perform valid
* inversions.
*/
long alwaysSetOutputBits = stamp.mustBeSet();
long alwaysSetExtensionBits = alwaysSetOutputBits >>> inputBits;
if (alwaysSetExtensionBits != 0) {
createEmptyStamp(inputBits);
long mustBeSetOutputBits = stamp.mustBeSet();
long mustBeSetExtensionBits = mustBeSetOutputBits >>> inputBits;
if (mustBeSetExtensionBits != 0) {
return createEmptyStamp(inputBits);
}

long inputMask = CodeUtil.mask(inputBits);
return StampFactory.forUnsignedInteger(inputBits, stamp.lowerBound(), stamp.upperBound(), stamp.mustBeSet() & inputMask, stamp.mayBeSet() & inputMask);
/*
* The output of a zero extend cannot be negative. Setting the lower
* bound > 0 enables inverting stamps like [-8, 16] without having to
* return an unrestricted stamp.
*/
long lowerBound = Math.max(stamp.lowerBound(), 0);
assert stamp.upperBound() >= 0 : "Cannot invert ZeroExtend for stamp with msb=1, which implies a negative value after ZeroExtend!";

return StampFactory.forUnsignedInteger(inputBits, lowerBound, stamp.upperBound(), stamp.mustBeSet(), stamp.mayBeSet());
}
},

Expand Down Expand Up @@ -2029,11 +2036,11 @@ public Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp) {
}

/*
* there is no guarantee that a given result bit is in the range of the
* There is no guarantee that a given result bit is in the range of the
* input because of holes in ranges resulting from signed / unsigned
* extension, so we must ensure that the extension bits are either all
* zeros or all ones otherwise we cannot represent the result, and we
* have to return an unrestricted stamp
* have to return an empty stamp.
*
* As an example:
* @formatter:off
Expand All @@ -2056,21 +2063,75 @@ public Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp) {
* ZeroExtend to get 0xb308, but then we try to invert the SignExtend.
* The sign extend could only have produced 0xff__ or 0x00__ from a byte
* but 0xb308 has 0xb3, and so we cannot invert the stamp. In this case
* the only sensible inversion is the unrestricted stamp.
* the only sensible inversion is the empty stamp.
*/
long alwaysSetOutputBits = stamp.mustBeSet();
long alwaysSetExtensionBits = alwaysSetOutputBits >>> inputBits;
long outputMask = CodeUtil.mask(resultBits);
if (alwaysSetExtensionBits != 0 && alwaysSetExtensionBits != (outputMask >>> inputBits)) {
long mustBeSetExtensionBits = stamp.mustBeSet() >>> inputBits;
long mayBeSetExtensionBits = stamp.mayBeSet() >>> inputBits;
long extensionMask = CodeUtil.mask(stamp.getBits()) >>> inputBits;

boolean zeroInExtension = mayBeSetExtensionBits != extensionMask;
boolean oneInExtension = mustBeSetExtensionBits != 0;
boolean inputMSBOne = significantBit(inputBits, stamp.mustBeSet()) == 1;
boolean inputMSBZero = significantBit(inputBits, stamp.mayBeSet()) == 0;

/*
* Checks for contradictions in the extension and returns an empty stamp in such cases.
* Examples for contradictions for a stamp after an artificial 4->8 bit sign extension:
*
* @formatter:off
*
* 1) 01xx xxxx --> extension cannot contain zeroes and ones
* 2) x0xx 1xxx --> extension cannot contain a zero if the MSB of the extended value is 1
* 3) xx1x 0xxx --> extension cannot contain a one if the MSB of the extended value is 0
*
* @formatter:on
*/
if ((zeroInExtension && oneInExtension) || (inputMSBOne && zeroInExtension) || (inputMSBZero && oneInExtension)) {
return createEmptyStamp(inputBits);
}

long inputMask = CodeUtil.mask(inputBits);
if (inputBits < stamp.getBits() && (stamp.contains(CodeUtil.minValue(inputBits) - 1) || stamp.contains(CodeUtil.maxValue(inputBits) + 1))) {
// Truncation will cause this value to wrap around
return create(inputBits).unrestricted();
long inputMustBeSet = stamp.mustBeSet() & inputMask;
long inputMayBeSet = stamp.mayBeSet() & inputMask;

if (!inputMSBOne && !inputMSBZero) {
/*
* Input MSB yet unknown, try to infer it from the extension:
*
* @formatter:off
*
* xx0x xxxx implies that the extension is 0000 which implies that the MSB of the input is 0
* x1xx xxxx implies that the extension is 1111 which implies that the MSB of the input is 1
*
* @formatter:on
*/
if (zeroInExtension) {
long msbZeroMask = ~(1 << (inputBits - 1));
inputMustBeSet &= msbZeroMask;
inputMayBeSet &= msbZeroMask;
} else if (oneInExtension) {
long msbOneMask = 1 << (inputBits - 1);
inputMustBeSet |= msbOneMask;
inputMayBeSet |= msbOneMask;
}
}
return StampFactory.forIntegerWithMask(inputBits, stamp.lowerBound(), stamp.upperBound(), stamp.mustBeSet() & inputMask, stamp.mayBeSet() & inputMask);

// Calculate conservative bounds for the input.
long inputUpperBound = maxValueForMasks(inputBits, inputMustBeSet, inputMayBeSet);
long inputLowerBound = minValueForMasks(inputBits, inputMustBeSet, inputMayBeSet);

/*
* If the bounds calculated for the input stamp do not overlap with the
* bounds for the stamp to invert, return an empty stamp. Otherwise,
* refine the conservative stamp for the input.
*/
if ((stamp.upperBound() < inputLowerBound) || (stamp.lowerBound() > inputUpperBound)) {
return createEmptyStamp(inputBits);
}
inputUpperBound = Math.min(inputUpperBound, stamp.upperBound());
inputLowerBound = Math.max(inputLowerBound, stamp.lowerBound());

return StampFactory.forIntegerWithMask(inputBits, inputLowerBound, inputUpperBound, inputMustBeSet, inputMayBeSet);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ public static IntegerStamp forUnsignedInteger(int bits, long unsignedLowerBound,
return forUnsignedInteger(bits, unsignedLowerBound, unsignedUpperBound, 0, CodeUtil.mask(bits));
}

/**
* Creates an IntegerStamp from the given unsigned bounds and bit masks. This method returns an
* empty stamp if the unsigned lower bound is larger than the unsigned upper bound. If the sign
* of lower and upper bound differs after sign extension to the specified length ({@code bits}),
* this method returns an unrestricted stamp with respect to the bounds. {@code mayBeSet} or
* {@code mustBeSet} can restrict the bounds nevertheless. Take the following example when
* inverting a zero extended 32bit stamp to the 8bit stamp before extension:
*
* </p>
* 32bit stamp [0, 192] 00...00 xxxxxxx0
* </p>
* When converting the bounds to 8bit, they have different signs, i.e.:
* </p>
* lowerUnsigned = 0000 0000 and upperUnsigned = 1100 0000
* </p>
* In order to respect the (unsigned) boundaries of the extended value, the signed input can be:
* </p>
* 0000 0000 - 0111 1111, i.e. 0 to 127 </br>
* or </br>
* 1000 0000 - 1100 0000, i.e. -128 to -64
* </p>
* The resulting interval [-128, -64]u[0, 127] cannot be represented by a single upper and lower
* bound. Thus, we have to return an unrestricted stamp, with respect to the bounds.
*/
public static IntegerStamp forUnsignedInteger(int bits, long unsignedLowerBound, long unsignedUpperBound, long mustBeSet, long mayBeSet) {
if (Long.compareUnsigned(unsignedLowerBound, unsignedUpperBound) > 0) {
return IntegerStamp.createEmptyStamp(bits);
Expand Down
Loading
Loading