Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (21 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28dir.info
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/verify.cc

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    11// defineclass.cc - defining a class from .class format.
    22
    3 /* Copyright (C) 2001, 2002  Free Software Foundation
     3/* Copyright (C) 2001, 2002, 2003  Free Software Foundation
    44
    55   This file is part of libgcj.
     
    127127
    128128    return r;
     129  }
     130
     131  __attribute__ ((__noreturn__)) void verify_fail (char *s, jint pc = -1)
     132  {
     133    using namespace java::lang;
     134    StringBuffer *buf = new StringBuffer ();
     135
     136    buf->append (JvNewStringLatin1 ("verification failed"));
     137    if (pc == -1)
     138      pc = start_PC;
     139    if (pc != -1)
     140      {
     141        buf->append (JvNewStringLatin1 (" at PC "));
     142        buf->append (pc);
     143      }
     144
     145    _Jv_InterpMethod *method = current_method;
     146    buf->append (JvNewStringLatin1 (" in "));
     147    buf->append (current_class->getName());
     148    buf->append ((jchar) ':');
     149    buf->append (JvNewStringUTF (method->get_method()->name->data));
     150    buf->append ((jchar) '(');
     151    buf->append (JvNewStringUTF (method->get_method()->signature->data));
     152    buf->append ((jchar) ')');
     153
     154    buf->append (JvNewStringLatin1 (": "));
     155    buf->append (JvNewStringLatin1 (s));
     156    throw new java::lang::VerifyError (buf->toString ());
    129157  }
    130158
     
    406434      using namespace java::lang;
    407435      java::lang::ClassLoader *loader
    408         = verifier->current_class->getClassLoader();
     436        = verifier->current_class->getClassLoaderInternal();
    409437      // We might see either kind of name.  Sigh.
    410438      if (data.name->data[0] == 'L'
     
    459487        return key == k.key;
    460488
    461       // The `null' type is convertible to any reference type.
    462       // FIXME: is this correct for THIS?
     489      // The `null' type is convertible to any initialized reference
     490      // type.
    463491      if (key == null_type || k.key == null_type)
    464492        return true;
     
    572600      if (key == reference_type)
    573601        return type (_Jv_GetArrayClass (data.klass,
    574                                         data.klass->getClassLoader ()));
     602                                        data.klass->getClassLoaderInternal()));
    575603      else
    576604        verifier->verify_fail ("internal error in type::to_array()");
     
    696724                        {
    697725                          java::lang::ClassLoader *loader
    698                             = verifier->current_class->getClassLoader();
     726                            = verifier->current_class->getClassLoaderInternal();
    699727                          k = _Jv_GetArrayClass (k, loader);
    700728                          --arraycount;
     
    794822    // without really initializing.
    795823    type this_type;
     824    // This is a list of all subroutines that have been seen at this
     825    // point.  Ordinarily this is NULL; it is only allocated and used
     826    // in relatively weird situations involving non-ret exit from a
     827    // subroutine.  We have to keep track of this in this way to avoid
     828    // endless recursion in these cases.
     829    subr_info *seen_subrs;
    796830
    797831    // INVALID marks a state which is not on the linked list of states
     
    812846      locals = NULL;
    813847      local_changed = NULL;
     848      seen_subrs = NULL;
    814849    }
    815850
     
    824859      locals = new type[max_locals];
    825860      local_changed = (bool *) _Jv_Malloc (sizeof (bool) * max_locals);
     861      seen_subrs = NULL;
    826862      for (int i = 0; i < max_locals; ++i)
    827863        {
     
    839875      locals = new type[max_locals];
    840876      local_changed = (bool *) _Jv_Malloc (sizeof (bool) * max_locals);
     877      seen_subrs = NULL;
    841878      copy (orig, max_stack, max_locals, ret_semantics);
    842879      next = INVALID;
     
    851888      if (local_changed)
    852889        _Jv_Free (local_changed);
     890      clean_subrs ();
    853891    }
    854892
     
    871909    {
    872910      _Jv_Free (mem);
     911    }
     912
     913    void clean_subrs ()
     914    {
     915      subr_info *info = seen_subrs;
     916      while (info != NULL)
     917        {
     918          subr_info *next = info->next;
     919          _Jv_Free (info);
     920          info = next;
     921        }
    873922    }
    874923
     
    892941          local_changed[i] = copy->local_changed[i];
    893942        }
     943
     944      clean_subrs ();
     945      if (copy->seen_subrs)
     946        {
     947          for (subr_info *info = seen_subrs; info != NULL; info = info->next)
     948            add_subr (info->pc);
     949        }
     950      else
     951        seen_subrs = NULL;
     952
    894953      this_type = copy->this_type;
    895954      // Don't modify `next'.
     
    916975      for (int i = 0; i < max_locals; ++i)
    917976        local_changed[i] = false;
     977    }
     978
     979    // Indicate that we've been in this this subroutine.
     980    void add_subr (int pc)
     981    {
     982      subr_info *n = (subr_info *) _Jv_Malloc (sizeof (subr_info));
     983      n->pc = pc;
     984      n->next = seen_subrs;
     985      seen_subrs = n;
    918986    }
    919987
     
    9451013      else
    9461014        {
    947           // If the subroutines differ, indicate that the state
    948           // changed.  This is needed to detect when subroutines have
    949           // merged.
    950           changed = true;
     1015          // If the subroutines differ, and we haven't seen this
     1016          // subroutine before, indicate that the state changed.  This
     1017          // is needed to detect when subroutines have merged.
     1018          bool found = false;
     1019          for (subr_info *info = seen_subrs; info != NULL; info = info->next)
     1020            {
     1021              if (info->pc == state_old->subroutine)
     1022                {
     1023                  found = true;
     1024                  break;
     1025                }
     1026            }
     1027          if (! found)
     1028            {
     1029              add_subr (state_old->subroutine);
     1030              changed = true;
     1031            }
    9511032        }
    9521033
     
    11221203  }
    11231204
    1124   type pop64 ()
    1125   {
    1126     type r = pop_raw ();
    1127     if (! r.iswide ())
    1128       verify_fail ("wide pop of narrow type");
    1129     return r;
    1130   }
    1131 
    11321205  type pop_type (type match)
    11331206  {
     
    11351208    type t = pop_raw ();
    11361209    if (! match.compatible (t, this))
     1210      verify_fail ("incompatible type on stack");
     1211    return t;
     1212  }
     1213
     1214  // Pop a reference which is guaranteed to be initialized.  MATCH
     1215  // doesn't have to be a reference type; in this case this acts like
     1216  // pop_type.
     1217  type pop_init_ref (type match)
     1218  {
     1219    type t = pop_raw ();
     1220    if (t.isreference () && ! t.isinitialized ())
     1221      verify_fail ("initialized reference required");
     1222    else if (! match.compatible (t, this))
    11371223      verify_fail ("incompatible type on stack");
    11381224    return t;
     
    13391425    int *prev_loc = &next_verify_pc;
    13401426    int npc = next_verify_pc;
    1341     bool skipped = false;
    13421427
    13431428    while (npc != state::NO_NEXT)
     
    13561441          }
    13571442
    1358         skipped = true;
    13591443        prev_loc = &states[npc]->next;
    13601444        npc = states[npc]->next;
     
    14351519    for (subr_info *subr = jsr_ptrs[csub]; subr != NULL; subr = subr->next)
    14361520      {
     1521        // We might be returning to a `jsr' that is at the end of the
     1522        // bytecode.  This is ok if we never return from the called
     1523        // subroutine, but if we see this here it is an error.
     1524        if (subr->pc >= current_method->code_length)
     1525          verify_fail ("fell off end");
     1526
    14371527        // Temporarily modify the current state so it looks like we're
    14381528        // in the enclosing context.
     
    14841574    // might change the stack depth, so we can't make any assumptions
    14851575    // about it.  So we have yet another special case.  We know that
    1486     // at this point PC points to the instruction after the jsr.
    1487 
    1488     // FIXME: what if we have a jsr at the end of the code, but that
    1489     // jsr has no corresponding ret?  Is this verifiable, or is it
    1490     // not?  If it is then we need a special case here.
    1491     if (PC >= current_method->code_length)
    1492       verify_fail ("fell off end");
    1493 
    1494     current_state->stacktop = state::NO_STACK;
    1495     push_jump_merge (PC, current_state);
     1576    // at this point PC points to the instruction after the jsr.  Note
     1577    // that it is ok to have a `jsr' at the end of the bytecode,
     1578    // provided that the called subroutine never returns.  So, we have
     1579    // a special case here and another one when we handle the ret.
     1580    if (PC < current_method->code_length)
     1581      {
     1582        current_state->stacktop = state::NO_STACK;
     1583        push_jump_merge (PC, current_state);
     1584      }
    14961585    invalidate_pc ();
    14971586  }
     
    15261615        k = JvPrimClass (long);
    15271616        break;
     1617
     1618      // These aren't used here but we call them out to avoid
     1619      // warnings.
     1620      case void_type:
     1621      case unsuitable_type:
     1622      case return_address_type:
     1623      case continuation_type:
     1624      case unused_by_subroutine_type:
     1625      case reference_type:
     1626      case null_type:
     1627      case unresolved_reference_type:
     1628      case uninitialized_reference_type:
     1629      case uninitialized_unresolved_reference_type:
    15281630      default:
    15291631        verify_fail ("unknown type in construct_primitive_array_type");
     
    18291931            break;
    18301932
     1933          // These are unused here, but we call them out explicitly
     1934          // so that -Wswitch-enum doesn't complain.
     1935          case op_putfield_1:
     1936          case op_putfield_2:
     1937          case op_putfield_4:
     1938          case op_putfield_8:
     1939          case op_putfield_a:
     1940          case op_putstatic_1:
     1941          case op_putstatic_2:
     1942          case op_putstatic_4:
     1943          case op_putstatic_8:
     1944          case op_putstatic_a:
     1945          case op_getfield_1:
     1946          case op_getfield_2s:
     1947          case op_getfield_2u:
     1948          case op_getfield_4:
     1949          case op_getfield_8:
     1950          case op_getfield_a:
     1951          case op_getstatic_1:
     1952          case op_getstatic_2s:
     1953          case op_getstatic_2u:
     1954          case op_getstatic_4:
     1955          case op_getstatic_8:
     1956          case op_getstatic_a:
    18311957          default:
    18321958            verify_fail ("unrecognized instruction in branch_prepass",
     
    18461972    for (int i = 0; i < current_method->exc_count; ++i)
    18471973      {
    1848         if (! (flags[exception[i].handler_pc] & FLAG_INSN_START))
     1974        if (! (flags[exception[i].handler_pc.i] & FLAG_INSN_START))
    18491975          verify_fail ("exception handler not at instruction start",
    1850                        exception[i].handler_pc);
    1851         if (! (flags[exception[i].start_pc] & FLAG_INSN_START))
     1976                       exception[i].handler_pc.i);
     1977        if (! (flags[exception[i].start_pc.i] & FLAG_INSN_START))
    18521978          verify_fail ("exception start not at instruction start",
    1853                        exception[i].start_pc);
    1854         if (exception[i].end_pc != current_method->code_length
    1855             && ! (flags[exception[i].end_pc] & FLAG_INSN_START))
     1979                       exception[i].start_pc.i);
     1980        if (exception[i].end_pc.i != current_method->code_length
     1981            && ! (flags[exception[i].end_pc.i] & FLAG_INSN_START))
    18561982          verify_fail ("exception end not at instruction start",
    1857                        exception[i].end_pc);
    1858 
    1859         flags[exception[i].handler_pc] |= FLAG_BRANCH_TARGET;
     1983                       exception[i].end_pc.i);
     1984
     1985        flags[exception[i].handler_pc.i] |= FLAG_BRANCH_TARGET;
    18601986      }
    18611987  }
     
    20272153  {
    20282154    int var = 0;
    2029     bool is_init = false;
     2155    bool is_init = _Jv_equalUtf8Consts (current_method->self->name,
     2156                                        gcj::init_name);
     2157    bool is_clinit = _Jv_equalUtf8Consts (current_method->self->name,
     2158                                          gcj::clinit_name);
    20302159
    20312160    using namespace java::lang::reflect;
     
    20332162      {
    20342163        type kurr (current_class);
    2035         if (_Jv_equalUtf8Consts (current_method->self->name, gcj::init_name))
     2164        if (is_init)
    20362165          {
    20372166            kurr.set_uninitialized (type::SELF, this);
    20382167            is_init = true;
    20392168          }
     2169        else if (is_clinit)
     2170          verify_fail ("<clinit> method must be static");
    20402171        set_variable (0, kurr);
    20412172        current_state->set_this_type (kurr);
    20422173        ++var;
     2174      }
     2175    else
     2176      {
     2177        if (is_init)
     2178          verify_fail ("<init> method must be non-static");
    20432179      }
    20442180
     
    21502286        for (int i = 0; i < current_method->exc_count; ++i)
    21512287          {
    2152             if (PC >= exception[i].start_pc && PC < exception[i].end_pc)
     2288            if (PC >= exception[i].start_pc.i && PC < exception[i].end_pc.i)
    21532289              {
    21542290                type handler (&java::lang::Throwable::class$);
    2155                 if (exception[i].handler_type != 0)
    2156                   handler = check_class_constant (exception[i].handler_type);
    2157                 push_exception_jump (handler, exception[i].handler_pc);
     2291                if (exception[i].handler_type.i != 0)
     2292                  handler = check_class_constant (exception[i].handler_type.i);
     2293                push_exception_jump (handler, exception[i].handler_pc.i);
    21582294              }
    21592295          }
     
    22652401          case op_iaload:
    22662402            pop_type (int_type);
    2267             push_type (require_array_type (pop_type (reference_type),
     2403            push_type (require_array_type (pop_init_ref (reference_type),
    22682404                                           int_type));
    22692405            break;
    22702406          case op_laload:
    22712407            pop_type (int_type);
    2272             push_type (require_array_type (pop_type (reference_type),
     2408            push_type (require_array_type (pop_init_ref (reference_type),
    22732409                                           long_type));
    22742410            break;
    22752411          case op_faload:
    22762412            pop_type (int_type);
    2277             push_type (require_array_type (pop_type (reference_type),
     2413            push_type (require_array_type (pop_init_ref (reference_type),
    22782414                                           float_type));
    22792415            break;
    22802416          case op_daload:
    22812417            pop_type (int_type);
    2282             push_type (require_array_type (pop_type (reference_type),
     2418            push_type (require_array_type (pop_init_ref (reference_type),
    22832419                                           double_type));
    22842420            break;
    22852421          case op_aaload:
    22862422            pop_type (int_type);
    2287             push_type (require_array_type (pop_type (reference_type),
     2423            push_type (require_array_type (pop_init_ref (reference_type),
    22882424                                           reference_type));
    22892425            break;
    22902426          case op_baload:
    22912427            pop_type (int_type);
    2292             require_array_type (pop_type (reference_type), byte_type);
     2428            require_array_type (pop_init_ref (reference_type), byte_type);
    22932429            push_type (int_type);
    22942430            break;
    22952431          case op_caload:
    22962432            pop_type (int_type);
    2297             require_array_type (pop_type (reference_type), char_type);
     2433            require_array_type (pop_init_ref (reference_type), char_type);
    22982434            push_type (int_type);
    22992435            break;
    23002436          case op_saload:
    23012437            pop_type (int_type);
    2302             require_array_type (pop_type (reference_type), short_type);
     2438            require_array_type (pop_init_ref (reference_type), short_type);
    23032439            push_type (int_type);
    23042440            break;
     
    23512487            pop_type (int_type);
    23522488            pop_type (int_type);
    2353             require_array_type (pop_type (reference_type), int_type);
     2489            require_array_type (pop_init_ref (reference_type), int_type);
    23542490            break;
    23552491          case op_lastore:
    23562492            pop_type (long_type);
    23572493            pop_type (int_type);
    2358             require_array_type (pop_type (reference_type), long_type);
     2494            require_array_type (pop_init_ref (reference_type), long_type);
    23592495            break;
    23602496          case op_fastore:
    23612497            pop_type (float_type);
    23622498            pop_type (int_type);
    2363             require_array_type (pop_type (reference_type), float_type);
     2499            require_array_type (pop_init_ref (reference_type), float_type);
    23642500            break;
    23652501          case op_dastore:
    23662502            pop_type (double_type);
    23672503            pop_type (int_type);
    2368             require_array_type (pop_type (reference_type), double_type);
     2504            require_array_type (pop_init_ref (reference_type), double_type);
    23692505            break;
    23702506          case op_aastore:
    23712507            pop_type (reference_type);
    23722508            pop_type (int_type);
    2373             require_array_type (pop_type (reference_type), reference_type);
     2509            require_array_type (pop_init_ref (reference_type), reference_type);
    23742510            break;
    23752511          case op_bastore:
    23762512            pop_type (int_type);
    23772513            pop_type (int_type);
    2378             require_array_type (pop_type (reference_type), byte_type);
     2514            require_array_type (pop_init_ref (reference_type), byte_type);
    23792515            break;
    23802516          case op_castore:
    23812517            pop_type (int_type);
    23822518            pop_type (int_type);
    2383             require_array_type (pop_type (reference_type), char_type);
     2519            require_array_type (pop_init_ref (reference_type), char_type);
    23842520            break;
    23852521          case op_sastore:
    23862522            pop_type (int_type);
    23872523            pop_type (int_type);
    2388             require_array_type (pop_type (reference_type), short_type);
     2524            require_array_type (pop_init_ref (reference_type), short_type);
    23892525            break;
    23902526          case op_pop:
     
    23922528            break;
    23932529          case op_pop2:
    2394             pop64 ();
     2530            {
     2531              type t = pop_raw ();
     2532              if (! t.iswide ())
     2533                pop32 ();
     2534            }
    23952535            break;
    23962536          case op_dup:
     
    27242864            break;
    27252865          case op_areturn:
    2726             check_return_type (pop_type (reference_type));
     2866            check_return_type (pop_init_ref (reference_type));
    27272867            invalidate_pc ();
    27282868            break;
     
    28062946                  // invokeinterface.
    28072947                  nargs -= arg_types[i].depth ();
    2808                   pop_type (arg_types[i]);
     2948                  pop_init_ref (arg_types[i]);
    28092949                }
    28102950
     
    28232963                  type raw = pop_raw ();
    28242964                  bool ok = false;
    2825                   if (t.compatible (raw, this))
     2965                  if (! is_init && ! raw.isinitialized ())
     2966                    {
     2967                      // This is a failure.
     2968                    }
     2969                  else if (is_init && raw.isnull ())
     2970                    {
     2971                      // Another failure.
     2972                    }
     2973                  else if (t.compatible (raw, this))
    28262974                    {
    28272975                      ok = true;
     
    28793027          case op_arraylength:
    28803028            {
    2881               type t = pop_type (reference_type);
     3029              type t = pop_init_ref (reference_type);
    28823030              if (! t.isarray () && ! t.isnull ())
    28833031                verify_fail ("array type expected");
     
    28903038            break;
    28913039          case op_checkcast:
    2892             pop_type (reference_type);
     3040            pop_init_ref (reference_type);
    28933041            push_type (check_class_constant (get_ushort ()));
    28943042            break;
    28953043          case op_instanceof:
    2896             pop_type (reference_type);
     3044            pop_init_ref (reference_type);
    28973045            check_class_constant (get_ushort ());
    28983046            push_type (int_type);
    28993047            break;
    29003048          case op_monitorenter:
    2901             pop_type (reference_type);
     3049            pop_init_ref (reference_type);
    29023050            break;
    29033051          case op_monitorexit:
    2904             pop_type (reference_type);
     3052            pop_init_ref (reference_type);
    29053053            break;
    29063054          case op_wide:
     
    29363084                  break;
    29373085                case op_astore:
    2938                   set_variable (get_ushort (), pop_type (reference_type));
     3086                  set_variable (get_ushort (), pop_init_ref (reference_type));
    29393087                  break;
    29403088                case op_ret:
     
    29753123            break;
    29763124
     3125          // These are unused here, but we call them out explicitly
     3126          // so that -Wswitch-enum doesn't complain.
     3127          case op_putfield_1:
     3128          case op_putfield_2:
     3129          case op_putfield_4:
     3130          case op_putfield_8:
     3131          case op_putfield_a:
     3132          case op_putstatic_1:
     3133          case op_putstatic_2:
     3134          case op_putstatic_4:
     3135          case op_putstatic_8:
     3136          case op_putstatic_a:
     3137          case op_getfield_1:
     3138          case op_getfield_2s:
     3139          case op_getfield_2u:
     3140          case op_getfield_4:
     3141          case op_getfield_8:
     3142          case op_getfield_a:
     3143          case op_getstatic_1:
     3144          case op_getstatic_2s:
     3145          case op_getstatic_2u:
     3146          case op_getstatic_4:
     3147          case op_getstatic_8:
     3148          case op_getstatic_a:
    29773149          default:
    29783150            // Unrecognized opcode.
     
    29813153          }
    29823154      }
    2983   }
    2984 
    2985   __attribute__ ((__noreturn__)) void verify_fail (char *s, jint pc = -1)
    2986   {
    2987     using namespace java::lang;
    2988     StringBuffer *buf = new StringBuffer ();
    2989 
    2990     buf->append (JvNewStringLatin1 ("verification failed"));
    2991     if (pc == -1)
    2992       pc = start_PC;
    2993     if (pc != -1)
    2994       {
    2995         buf->append (JvNewStringLatin1 (" at PC "));
    2996         buf->append (pc);
    2997       }
    2998 
    2999     _Jv_InterpMethod *method = current_method;
    3000     buf->append (JvNewStringLatin1 (" in "));
    3001     buf->append (current_class->getName());
    3002     buf->append ((jchar) ':');
    3003     buf->append (JvNewStringUTF (method->get_method()->name->data));
    3004     buf->append ((jchar) '(');
    3005     buf->append (JvNewStringUTF (method->get_method()->signature->data));
    3006     buf->append ((jchar) ')');
    3007 
    3008     buf->append (JvNewStringLatin1 (": "));
    3009     buf->append (JvNewStringLatin1 (s));
    3010     throw new java::lang::VerifyError (buf->toString ());
    30113155  }
    30123156
Note: See TracChangeset for help on using the changeset viewer.