2006-11-22 17:38:46 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.ibm.wala.classLoader;
|
|
|
|
|
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
|
|
|
|
/**
|
2007-12-17 14:31:17 +00:00
|
|
|
* Simple object that represents a program counter value (i.e., an instruction in
|
2007-04-24 15:17:52 +00:00
|
|
|
* the bytecode)
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
|
|
|
* @author sfink
|
|
|
|
*/
|
|
|
|
public class ProgramCounter implements IProgramCounter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Index into bytecode describing this instruction
|
|
|
|
*/
|
|
|
|
private final int programCounter;
|
|
|
|
|
|
|
|
/**
|
2007-04-24 15:17:52 +00:00
|
|
|
* @param programCounter
|
|
|
|
* Index into bytecode describing this instruction
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
|
|
|
public ProgramCounter(final int programCounter) {
|
|
|
|
if (Assertions.verifyAssertions) {
|
|
|
|
Assertions._assert(programCounter >= 0);
|
|
|
|
}
|
|
|
|
this.programCounter = programCounter;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-04-24 15:17:52 +00:00
|
|
|
* Return the program counter (index into the method's bytecode) for this call
|
|
|
|
* site.
|
|
|
|
*
|
|
|
|
* @return the program counter (index into the method's bytecode) for this
|
|
|
|
* call site.
|
|
|
|
*
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
|
|
|
public int getProgramCounter() {
|
|
|
|
return programCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-04-24 15:17:52 +00:00
|
|
|
* A Program Counter value is enough to uniquely identify a call site
|
|
|
|
* reference within a method.
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
2007-04-24 15:17:52 +00:00
|
|
|
* Note: must use these objects with extreme care; this only works if you
|
|
|
|
* never mix ProgramLocations from different methods in the same collection.
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
|
|
|
* @see java.lang.Object#equals(Object)
|
|
|
|
*/
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public boolean equals(Object obj) {
|
2007-04-24 15:17:52 +00:00
|
|
|
return (obj instanceof ProgramCounter) && ((ProgramCounter) obj).programCounter == programCounter;
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
2007-04-24 15:17:52 +00:00
|
|
|
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public int hashCode() {
|
2007-12-17 14:31:17 +00:00
|
|
|
return programCounter + 77;
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public String toString() {
|
|
|
|
return "PC@" + programCounter;
|
|
|
|
}
|
|
|
|
}
|