ThrowException .-.
This commit is contained in:
parent
45d0aa66e5
commit
6b03cab14d
4 changed files with 14 additions and 5 deletions
|
@ -251,6 +251,7 @@ impl Bytecode {
|
||||||
0xBC => (Instruction::NewPrimitiveArray(self.bytes[offset+1]), 2),
|
0xBC => (Instruction::NewPrimitiveArray(self.bytes[offset+1]), 2),
|
||||||
0xBD => (Instruction::NewArray((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
|
0xBD => (Instruction::NewArray((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
|
||||||
0xBE => (Instruction::ArrayLength(), 1),
|
0xBE => (Instruction::ArrayLength(), 1),
|
||||||
|
0xBF => (Instruction::ThrowException(), 1),
|
||||||
|
|
||||||
0xC0 => (Instruction::CheckCast((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
|
0xC0 => (Instruction::CheckCast((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
|
||||||
0xC1 => (Instruction::InstanceOf((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
|
0xC1 => (Instruction::InstanceOf((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
|
||||||
|
@ -446,6 +447,7 @@ pub enum Instruction {
|
||||||
NewPrimitiveArray(u8) = 0xBC, // make a primitive array
|
NewPrimitiveArray(u8) = 0xBC, // make a primitive array
|
||||||
NewArray(u16) = 0xBD, // Create a new array from a constant-pool component class reference
|
NewArray(u16) = 0xBD, // Create a new array from a constant-pool component class reference
|
||||||
ArrayLength() = 0xBE, // Get length from array reference
|
ArrayLength() = 0xBE, // Get length from array reference
|
||||||
|
ThrowException() = 0xBF, // throw the exception
|
||||||
|
|
||||||
CheckCast(u16) = 0xC0, // throw exception on fail
|
CheckCast(u16) = 0xC0, // throw exception on fail
|
||||||
InstanceOf(u16) = 0xC1, // push integer result for success
|
InstanceOf(u16) = 0xC1, // push integer result for success
|
||||||
|
|
|
@ -194,7 +194,7 @@ impl JavaClassFile {
|
||||||
|
|
||||||
pub fn find_method_index(&self, name: &String) -> Option<usize> {
|
pub fn find_method_index(&self, name: &String) -> Option<usize> {
|
||||||
|
|
||||||
for (index, method_info) in self.methods.iter().enumerate() {
|
for (index, method_info) in (&self.methods).into_iter().enumerate() {
|
||||||
if method_info.name == *name {
|
if method_info.name == *name {
|
||||||
return Some(index);
|
return Some(index);
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ impl JavaClassFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sourcefile(&self) -> Result<Option<&String>, Error> {
|
pub fn sourcefile(&self) -> Result<Option<&String>, Error> {
|
||||||
match self.attributes.into_iter()
|
match (&self.attributes).into_iter()
|
||||||
.filter_map(|attribute| match &attribute.data {
|
.filter_map(|attribute| match &attribute.data {
|
||||||
AttributeData::SourceFile(data) => Some(data),
|
AttributeData::SourceFile(data) => Some(data),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -1103,7 +1103,7 @@ impl MethodInfo {
|
||||||
|
|
||||||
pub fn get_bytecode_linenumber(&self, bytecode_index: u16) -> Option<u16> {
|
pub fn get_bytecode_linenumber(&self, bytecode_index: u16) -> Option<u16> {
|
||||||
let linenumbertable = match self.attributes
|
let linenumbertable = match self.attributes
|
||||||
.into_iter()
|
.iter()
|
||||||
.filter_map(|a| match &a.data {
|
.filter_map(|a| match &a.data {
|
||||||
AttributeData::LineNumberTable(data) => Some(data),
|
AttributeData::LineNumberTable(data) => Some(data),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -1112,7 +1112,7 @@ impl MethodInfo {
|
||||||
Some(a) => a,
|
Some(a) => a,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
linenumbertable.entries.into_iter()
|
linenumbertable.entries.iter()
|
||||||
.take_while(|entry| entry.start_pc < bytecode_index)
|
.take_while(|entry| entry.start_pc < bytecode_index)
|
||||||
.map(|entry| entry.line_number)
|
.map(|entry| entry.line_number)
|
||||||
.last()
|
.last()
|
||||||
|
|
|
@ -2278,6 +2278,13 @@ impl JVM {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Instruction::ThrowException() => {
|
||||||
|
let exception = wrap_stackframe_error(class, method, frame.operand_stack.pop_reference(0))?;
|
||||||
|
if exception == ObjectReference::NULL {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Instruction::XorInt() => {
|
Instruction::XorInt() => {
|
||||||
let value_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
|
let value_1 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
|
||||||
let value_2 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
|
let value_2 = wrap_stackframe_error(class, method, frame.operand_stack.pop_int(0))?;
|
||||||
|
|
|
@ -422,7 +422,7 @@ impl JavaLangThrowable {
|
||||||
let sourcefile = class_file.sourcefile()?;
|
let sourcefile = class_file.sourcefile()?;
|
||||||
let sourcefile_string = match sourcefile {
|
let sourcefile_string = match sourcefile {
|
||||||
Some(string) => jvm.heap_area.make_handmade_string(string, &jvm.class_store),
|
Some(string) => jvm.heap_area.make_handmade_string(string, &jvm.class_store),
|
||||||
None => jvm.heap_area.static_area.get(&String::from("StackTraceElement"), &String::from("UNKNOWN_SOURCE"), AbstractTypeDescription::class_type("java/lang/String")).unwrap().expect_reference(),
|
None => jvm.heap_area.static_area.get(&String::from("java/lang/StackTraceElement"), &String::from("UNKNOWN_SOURCE"), AbstractTypeDescription::class_type("java/lang/String")).unwrap().expect_reference(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jvm.heap_area.object_area.set_object_field(
|
jvm.heap_area.object_area.set_object_field(
|
||||||
|
|
Loading…
Reference in a new issue