hotspot/src/share/vm/oops/constMethodOop.cpp
changeset 13282 9872915dd78d
parent 12937 0032fb2caff6
--- a/hotspot/src/share/vm/oops/constMethodOop.cpp	Mon Jun 25 15:34:06 2012 -0400
+++ b/hotspot/src/share/vm/oops/constMethodOop.cpp	Tue Jun 26 19:08:44 2012 -0400
@@ -35,6 +35,7 @@
 int constMethodOopDesc::object_size(int code_size,
                                     int compressed_line_number_size,
                                     int local_variable_table_length,
+                                    int exception_table_length,
                                     int checked_exceptions_length) {
   int extra_bytes = code_size;
   if (compressed_line_number_size > 0) {
@@ -49,6 +50,10 @@
     extra_bytes +=
               local_variable_table_length * sizeof(LocalVariableTableElement);
   }
+  if (exception_table_length > 0) {
+    extra_bytes += sizeof(u2);
+    extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
+  }
   int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
   return align_object_size(header_size() + extra_words);
 }
@@ -73,23 +78,40 @@
   return last_u2_element();
 }
 
-u2* constMethodOopDesc::localvariable_table_length_addr() const {
-  assert(has_localvariable_table(), "called only if table is present");
+u2* constMethodOopDesc::exception_table_length_addr() const {
+  assert(has_exception_handler(), "called only if table is present");
   if (has_checked_exceptions()) {
     // If checked_exception present, locate immediately before them.
     return (u2*) checked_exceptions_start() - 1;
   } else {
-    // Else, the linenumber table is at the end of the constMethod.
+    // Else, the exception table is at the end of the constMethod.
     return last_u2_element();
   }
 }
 
+u2* constMethodOopDesc::localvariable_table_length_addr() const {
+  assert(has_localvariable_table(), "called only if table is present");
+  if (has_exception_handler()) {
+    // If exception_table present, locate immediately before them.
+    return (u2*) exception_table_start() - 1;
+  } else {
+    if (has_checked_exceptions()) {
+      // If checked_exception present, locate immediately before them.
+      return (u2*) checked_exceptions_start() - 1;
+    } else {
+      // Else, the linenumber table is at the end of the constMethod.
+      return last_u2_element();
+    }
+  }
+}
+
 
 // Update the flags to indicate the presence of these optional fields.
 void constMethodOopDesc::set_inlined_tables_length(
                                               int checked_exceptions_len,
                                               int compressed_line_number_size,
-                                              int localvariable_table_len) {
+                                              int localvariable_table_len,
+                                              int exception_table_len) {
   // Must be done in the order below, otherwise length_addr accessors
   // will not work. Only set bit in header if length is positive.
   assert(_flags == 0, "Error");
@@ -100,6 +122,10 @@
     _flags |= _has_checked_exceptions;
     *(checked_exceptions_length_addr()) = checked_exceptions_len;
   }
+  if (exception_table_len > 0) {
+    _flags |= _has_exception_table;
+    *(exception_table_length_addr()) = exception_table_len;
+  }
   if (localvariable_table_len > 0) {
     _flags |= _has_localvariable_table;
     *(localvariable_table_length_addr()) = localvariable_table_len;
@@ -133,3 +159,15 @@
   addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
   return (LocalVariableTableElement*) addr;
 }
+
+int constMethodOopDesc::exception_table_length() const {
+  return has_exception_handler() ? *(exception_table_length_addr()) : 0;
+}
+
+ExceptionTableElement* constMethodOopDesc::exception_table_start() const {
+  u2* addr = exception_table_length_addr();
+  u2 length = *addr;
+  assert(length > 0, "should only be called if table is present");
+  addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
+  return (ExceptionTableElement*)addr;
+}