comparison src/share/vm/classfile/verifier.cpp @ 726:be93aad57795

6655646: dynamic languages need dynamically linked call sites Summary: invokedynamic instruction (JSR 292 RI) Reviewed-by: twisti, never
author jrose
date Tue, 21 Apr 2009 23:21:04 -0700
parents a45484ea312d
children bd02caa94611
comparison
equal deleted inserted replaced
725:928912ce8438 726:be93aad57795
1172 verify_invoke_instructions( 1172 verify_invoke_instructions(
1173 &bcs, code_length, &current_frame, 1173 &bcs, code_length, &current_frame,
1174 &this_uninit, return_type, cp, CHECK_VERIFY(this)); 1174 &this_uninit, return_type, cp, CHECK_VERIFY(this));
1175 no_control_flow = false; break; 1175 no_control_flow = false; break;
1176 case Bytecodes::_invokeinterface : 1176 case Bytecodes::_invokeinterface :
1177 case Bytecodes::_invokedynamic :
1177 verify_invoke_instructions( 1178 verify_invoke_instructions(
1178 &bcs, code_length, &current_frame, 1179 &bcs, code_length, &current_frame,
1179 &this_uninit, return_type, cp, CHECK_VERIFY(this)); 1180 &this_uninit, return_type, cp, CHECK_VERIFY(this));
1180 no_control_flow = false; break; 1181 no_control_flow = false; break;
1181 case Bytecodes::_new : 1182 case Bytecodes::_new :
1893 // Make sure the constant pool item is the right type 1894 // Make sure the constant pool item is the right type
1894 u2 index = bcs->get_index_big(); 1895 u2 index = bcs->get_index_big();
1895 Bytecodes::Code opcode = bcs->code(); 1896 Bytecodes::Code opcode = bcs->code();
1896 unsigned int types = (opcode == Bytecodes::_invokeinterface 1897 unsigned int types = (opcode == Bytecodes::_invokeinterface
1897 ? 1 << JVM_CONSTANT_InterfaceMethodref 1898 ? 1 << JVM_CONSTANT_InterfaceMethodref
1899 : opcode == Bytecodes::_invokedynamic
1900 ? 1 << JVM_CONSTANT_NameAndType
1898 : 1 << JVM_CONSTANT_Methodref); 1901 : 1 << JVM_CONSTANT_Methodref);
1899 verify_cp_type(index, cp, types, CHECK_VERIFY(this)); 1902 verify_cp_type(index, cp, types, CHECK_VERIFY(this));
1900 1903
1901 // Get method name and signature 1904 // Get method name and signature
1902 symbolHandle method_name(THREAD, cp->name_ref_at(index)); 1905 symbolHandle method_name;
1903 symbolHandle method_sig(THREAD, cp->signature_ref_at(index)); 1906 symbolHandle method_sig;
1907 if (opcode == Bytecodes::_invokedynamic) {
1908 int name_index = cp->name_ref_index_at(index);
1909 int sig_index = cp->signature_ref_index_at(index);
1910 method_name = symbolHandle(THREAD, cp->symbol_at(name_index));
1911 method_sig = symbolHandle(THREAD, cp->symbol_at(sig_index));
1912 } else {
1913 method_name = symbolHandle(THREAD, cp->name_ref_at(index));
1914 method_sig = symbolHandle(THREAD, cp->signature_ref_at(index));
1915 }
1904 1916
1905 if (!SignatureVerifier::is_valid_method_signature(method_sig)) { 1917 if (!SignatureVerifier::is_valid_method_signature(method_sig)) {
1906 class_format_error( 1918 class_format_error(
1907 "Invalid method signature in class %s referenced " 1919 "Invalid method signature in class %s referenced "
1908 "from constant pool index %d", _klass->external_name(), index); 1920 "from constant pool index %d", _klass->external_name(), index);
1909 return; 1921 return;
1910 } 1922 }
1911 1923
1912 // Get referenced class type 1924 // Get referenced class type
1913 VerificationType ref_class_type = cp_ref_index_to_type( 1925 VerificationType ref_class_type;
1914 index, cp, CHECK_VERIFY(this)); 1926 if (opcode == Bytecodes::_invokedynamic) {
1927 if (!EnableInvokeDynamic) {
1928 class_format_error(
1929 "invokedynamic instructions not enabled on this JVM",
1930 _klass->external_name());
1931 return;
1932 }
1933 } else {
1934 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this));
1935 }
1915 1936
1916 // For a small signature length, we just allocate 128 bytes instead 1937 // For a small signature length, we just allocate 128 bytes instead
1917 // of parsing the signature once to find its size. 1938 // of parsing the signature once to find its size.
1918 // -3 is for '(', ')' and return descriptor; multiply by 2 is for 1939 // -3 is for '(', ')' and return descriptor; multiply by 2 is for
1919 // longs/doubles to be consertive. 1940 // longs/doubles to be consertive.
1968 verify_error(bci, "Fourth operand byte of invokeinterface must be zero"); 1989 verify_error(bci, "Fourth operand byte of invokeinterface must be zero");
1969 return; 1990 return;
1970 } 1991 }
1971 } 1992 }
1972 1993
1994 if (opcode == Bytecodes::_invokedynamic) {
1995 address bcp = bcs->bcp();
1996 if (*(bcp+3) != 0 || *(bcp+4) != 0) {
1997 verify_error(bci, "Third and fourth operand bytes of invokedynamic must be zero");
1998 return;
1999 }
2000 }
2001
1973 if (method_name->byte_at(0) == '<') { 2002 if (method_name->byte_at(0) == '<') {
1974 // Make sure <init> can only be invoked by invokespecial 2003 // Make sure <init> can only be invoked by invokespecial
1975 if (opcode != Bytecodes::_invokespecial || 2004 if (opcode != Bytecodes::_invokespecial ||
1976 method_name() != vmSymbols::object_initializer_name()) { 2005 method_name() != vmSymbols::object_initializer_name()) {
1977 verify_error(bci, "Illegal call to internal method"); 2006 verify_error(bci, "Illegal call to internal method");
1992 // Match method descriptor with operand stack 2021 // Match method descriptor with operand stack
1993 for (int i = nargs - 1; i >= 0; i--) { // Run backwards 2022 for (int i = nargs - 1; i >= 0; i--) { // Run backwards
1994 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); 2023 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
1995 } 2024 }
1996 // Check objectref on operand stack 2025 // Check objectref on operand stack
1997 if (opcode != Bytecodes::_invokestatic) { 2026 if (opcode != Bytecodes::_invokestatic &&
2027 opcode != Bytecodes::_invokedynamic) {
1998 if (method_name() == vmSymbols::object_initializer_name()) { // <init> method 2028 if (method_name() == vmSymbols::object_initializer_name()) { // <init> method
1999 verify_invoke_init(bcs, ref_class_type, current_frame, 2029 verify_invoke_init(bcs, ref_class_type, current_frame,
2000 code_length, this_uninit, cp, CHECK_VERIFY(this)); 2030 code_length, this_uninit, cp, CHECK_VERIFY(this));
2001 } else { // other methods 2031 } else { // other methods
2002 // Ensures that target class is assignable to method class. 2032 // Ensures that target class is assignable to method class.