Skip to content

Commit

Permalink
[FIXED JENKINS-41852] Tweak pinning logic
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Feb 10, 2017
1 parent 059b893 commit 849e015
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/hudson/remoting/ExportTable.java
Expand Up @@ -118,8 +118,19 @@ void addRef() {
* (and we can still detect the problem by comparing the reference count with the magic value.
*/
void pin() {
if (referenceCount<Integer.MAX_VALUE/2)
referenceCount += Integer.MAX_VALUE/2;
// only add the magic constant if we are in the range Integer.MIN_VALUE < x < 0x2000000
// this means that over-reference removal will still yield a referece above 0 and repeated pinning
// will not yield a negative reference count.
// e.g. if we had:
// init -> 0x00000000;
// pin -> 0x40000001;
// release -> 0x39999999;
// pin -> 0x79999999;
// addRef -> 0x80000000 => BOOM
// By making the decision point half way, we give the maximum number of releases away from the pinned
// magic value
if (referenceCount<0x20000000)
referenceCount += 0x40000000;
}

void release(Throwable callSite) {
Expand Down

0 comments on commit 849e015

Please sign in to comment.