src/share/vm/oops/method.cpp
Print this page
@@ -579,20 +579,61 @@
bool Method::can_be_statically_bound() const {
return can_be_statically_bound(method_holder()->access_flags());
}
-bool Method::is_accessor() const {
+bool Method::is_simple_accessor() const {
if (code_size() != 5) return false;
if (size_of_parameters() != 1) return false;
if (java_code_at(0) != Bytecodes::_aload_0 ) return false;
if (java_code_at(1) != Bytecodes::_getfield) return false;
if (java_code_at(4) != Bytecodes::_areturn &&
java_code_at(4) != Bytecodes::_ireturn ) return false;
return true;
}
+bool Method::is_accessor() const {
+ if (code_size() == 5) { // potential getter
+ if (size_of_parameters() != 1) return false;
+ if (java_code_at(0) != Bytecodes::_aload_0) return false;
+ if (java_code_at(1) != Bytecodes::_getfield) return false;
+ switch (java_code_at(4)) {
+ case Bytecodes::_ireturn:
+ case Bytecodes::_lreturn:
+ case Bytecodes::_freturn:
+ case Bytecodes::_dreturn:
+ case Bytecodes::_areturn:
+ break;
+ default:
+ return false;
+ }
+ return true;
+ }
+
+ if (code_size() == 6) { // potential setter
+ if (java_code_at(0) != Bytecodes::_aload_0) return false;
+ switch (java_code_at(1)) {
+ case Bytecodes::_iload_1:
+ case Bytecodes::_aload_1:
+ case Bytecodes::_fload_1:
+ if (size_of_parameters() != 2) return false;
+ break;
+ case Bytecodes::_dload_1:
+ case Bytecodes::_lload_1:
+ if (size_of_parameters() != 3) return false;
+ break;
+ default:
+ return false;
+ }
+ if (java_code_at(2) != Bytecodes::_putfield) return false;
+ if (java_code_at(5) != Bytecodes::_return) return false;
+ return true;
+ }
+
+ return false;
+}
+
bool Method::is_constant_getter() const {
int last_index = code_size() - 1;
// Check if the first 1-3 bytecodes are a constant push
// and the last bytecode is a return.
return (2 <= code_size() && code_size() <= 4 &&