#4 Update of ExceptionHandlers

closed-fixed
Core (15)
5
2007-02-26
2007-02-26
No

Hi,

the problem with the exception handlers is worse than we found in the last patch: The same Handler can be used in different bytecodes and when it is updated in one place it must not be updated again for another instruction.

So what is needed here is an IndentityHashSet that keeps track of Handlers that have been updated already instead of a normal HashSet.

Here's the Patch:

Index: src/com/ibm/wala/shrikeBT/MethodEditor.java

--- src/com/ibm/wala/shrikeBT/MethodEditor.java (revision 705)
+++ src/com/ibm/wala/shrikeBT/MethodEditor.java (working copy)
@@ -11,7 +11,7 @@
package com.ibm.wala.shrikeBT;

import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.IdentityHashMap;

/**
* The MethodEditor is the core of the ShrikeBT code rewriting mechanism. To
@@ -603,7 +603,7 @@
}

// We want to update each exception handler array exactly once
- HashSet<ExceptionHandler> adjustedHandlers = null;
+ IdentityHashMap<ExceptionHandler, Object> adjustedHandlers = null;
for (int i = 0; i < handlers.length; i++) {
ExceptionHandler[] hs = handlers[i];
if (hs.length > 0 && (i == 0 || hs != handlers[i - 1])) {
@@ -608,7 +608,7 @@
ExceptionHandler[] hs = handlers[i];
if (hs.length > 0 && (i == 0 || hs != handlers[i - 1])) {
if (adjustedHandlers == null) {
- adjustedHandlers = new HashSet<ExceptionHandler>();
+ adjustedHandlers = new IdentityHashMap<ExceptionHandler, Object>();
}

for (int j = 0; j < hs.length; j++) {
@@ -613,9 +613,9 @@

for (int j = 0; j < hs.length; j++) {
ExceptionHandler h = hs[j];
- if (!adjustedHandlers.contains(h)) {
- h.handler = labelDefs[h.handler];
- adjustedHandlers.add(h);
+ if (!adjustedHandlers.containsKey(h)) {
+ adjustedHandlers.put(h, null);
+ h.handler = labelDefs[h.handler]; // breaks invariant of ExceptionHandler: immutable!
}
}
}

Discussion

  • Stephen Fink

    Stephen Fink - 2007-02-26
    • labels: --> Core
    • assigned_to: nobody --> sjfink
    • status: open --> closed-fixed
     
  • Stephen Fink

    Stephen Fink - 2007-02-26

    Logged In: YES
    user_id=221724
    Originator: NO

    checked in.