Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 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
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/lang/natClass.cc

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    11// natClass.cc - Implementation of java.lang.Class native methods.
    22
    3 /* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
     3/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
    44
    55   This file is part of libgcj.
     
    3737#include <java/lang/IllegalArgumentException.h>
    3838#include <java/lang/IncompatibleClassChangeError.h>
     39
    3940#include <java/lang/InstantiationException.h>
    4041#include <java/lang/NoClassDefFoundError.h>
     
    4849#include <java/lang/SecurityManager.h>
    4950#include <java/lang/StringBuffer.h>
     51
    5052#include <gcj/method.h>
     53
     54
    5155
    5256#include <java-cpool.h>
    53 
    54 
    55 
    56 
    57 // FIXME: remove these.
    58 #define CloneableClass java::lang::Cloneable::class$
    59 #define ObjectClass java::lang::Object::class$
    60 #define ErrorClass java::lang::Error::class$
    61 #define ClassClass java::lang::Class::class$
    62 #define MethodClass java::lang::reflect::Method::class$
    63 #define FieldClass java::lang::reflect::Field::class$
    64 #define ConstructorClass java::lang::reflect::Constructor::class$
    6557
    6658
     
    8577    throw new java::lang::ClassNotFoundException (className);
    8678
    87   // FIXME: should use bootstrap class loader if loader is null.
    8879  jclass klass = (buffer[0] == '['
    8980                  ? _Jv_FindClassFromSignature (name->data, loader)
     
    10293java::lang::Class::forName (jstring className)
    10394{
    104   // FIXME: should use class loader from calling method.
    105   return forName (className, true, NULL);
     95  java::lang::ClassLoader *loader = NULL;
     96  gnu::gcj::runtime::StackTrace *t
     97    = new gnu::gcj::runtime::StackTrace(4);
     98  java::lang::Class *klass = NULL;
     99  try
     100    {
     101      for (int i = 1; !klass; i++)
     102        {
     103          klass = t->classAt (i);
     104        }
     105      loader = klass->getClassLoader();
     106    }
     107  catch (::java::lang::ArrayIndexOutOfBoundsException *e)
     108    {
     109    }
     110
     111  return forName (className, true, loader);
    106112}
    107113
     
    177183  JArray<java::lang::reflect::Constructor *> *result
    178184    = (JArray<java::lang::reflect::Constructor *> *)
    179     JvNewObjectArray (numConstructors, &ConstructorClass, NULL);
     185    JvNewObjectArray (numConstructors,
     186                      &java::lang::reflect::Constructor::class$,
     187                      NULL);
    180188  java::lang::reflect::Constructor** cptr = elements (result);
    181189  for (i = 0;  i < max;  i++)
     
    276284  JArray<java::lang::reflect::Field *> *result
    277285    = (JArray<java::lang::reflect::Field *> *)
    278     JvNewObjectArray (field_count, &FieldClass, NULL);
     286    JvNewObjectArray (field_count, &, NULL);
    279287  java::lang::reflect::Field** fptr = elements (result);
    280288  for (int i = 0;  i < field_count;  i++)
     
    327335
    328336java::lang::reflect::Method *
    329 java::lang::Class::getDeclaredMethod (jstring name,
    330                                       JArray<jclass> *param_types)
     337java::lang::Class::getDeclaredMethod (jstring name,
     338                                      JArray<jclass> *param_types)
    331339{
    332340  jstring partial_sig = getSignature (param_types, false);
     
    336344  while (--i >= 0)
    337345    {
    338       // FIXME: access checks.
    339346      if (_Jv_equalUtf8Consts (methods[i].name, utf_name)
    340           && _Jv_equaln (methods[i].signature, partial_sig, p_len))
     347          && _Jv_equaln (methods[i].signature, partial_sig, p_len)
     348          && (methods[i].accflags
     349              & java::lang::reflect::Modifier::INVISIBLE) == 0)
    341350        {
    342351          // Found it.
     
    348357        }
    349358    }
    350   throw new java::lang::NoSuchMethodException;
     359  ;
    351360}
    352361
     
    363372          || _Jv_equalUtf8Consts (method->name, clinit_name)
    364373          || _Jv_equalUtf8Consts (method->name, init_name)
    365           || _Jv_equalUtf8Consts (method->name, finit_name))
     374          || _Jv_equalUtf8Consts (method->name, finit_name)
     375          || (methods[i].accflags
     376              & java::lang::reflect::Modifier::INVISIBLE) != 0)
    366377        continue;
    367378      numMethods++;
     
    369380  JArray<java::lang::reflect::Method *> *result
    370381    = (JArray<java::lang::reflect::Method *> *)
    371     JvNewObjectArray (numMethods, &MethodClass, NULL);
     382    JvNewObjectArray (numMethods, &, NULL);
    372383  java::lang::reflect::Method** mptr = elements (result);
    373384  for (i = 0;  i < max;  i++)
     
    377388          || _Jv_equalUtf8Consts (method->name, clinit_name)
    378389          || _Jv_equalUtf8Consts (method->name, init_name)
    379           || _Jv_equalUtf8Consts (method->name, finit_name))
     390          || _Jv_equalUtf8Consts (method->name, finit_name)
     391          || (methods[i].accflags
     392              & java::lang::reflect::Modifier::INVISIBLE) != 0)
    380393        continue;
    381394      java::lang::reflect::Method* rmethod
     
    405418  // empty array.
    406419  JArray<jclass> *result
    407     = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
     420    = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
     421                                           NULL);
    408422  return result;
    409423}
     
    416430  // empty array.
    417431  JArray<jclass> *result
    418     = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
     432    = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
     433                                           NULL);
    419434  return result;
    420435}
     
    477492  JArray<java::lang::reflect::Field *> *result
    478493    = ((JArray<java::lang::reflect::Field *> *)
    479        JvNewObjectArray (count, &FieldClass, NULL));
     494       JvNewObjectArray (count, &, NULL));
    480495
    481496  _getFields (result, 0);
     
    495510
    496511java::lang::reflect::Method *
    497 java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
     512java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
    498513{
    499514  jstring partial_sig = getSignature (param_types, false);
     
    507522          // FIXME: access checks.
    508523          if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
    509               && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len))
     524              && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len)
     525              && (klass->methods[i].accflags
     526                  & java::lang::reflect::Modifier::INVISIBLE) == 0)
    510527            {
    511528              // Found it.
     
    524541        }
    525542    }
    526   throw new java::lang::NoSuchMethodException;
     543
     544  // If we haven't found a match, and this class is an interface, then
     545  // check all the superinterfaces.
     546  if (isInterface())
     547    {
     548      for (int i = 0; i < interface_count; ++i)
     549        {
     550          using namespace java::lang::reflect;
     551          Method *rmethod = interfaces[i]->_getMethod (name, param_types);
     552          if (rmethod != NULL)
     553            return rmethod;
     554        }
     555    }
     556
     557  return NULL;
    527558}
    528559
     
    544575          || _Jv_equalUtf8Consts (method->name, clinit_name)
    545576          || _Jv_equalUtf8Consts (method->name, init_name)
    546           || _Jv_equalUtf8Consts (method->name, finit_name))
     577          || _Jv_equalUtf8Consts (method->name, finit_name)
     578          || (method->accflags
     579              & java::lang::reflect::Modifier::INVISIBLE) != 0)
    547580        continue;
    548581      // Only want public methods.
     
    617650
    618651  JArray<Method *> *result
    619     = ((JArray<Method *> *) JvNewObjectArray (count, &MethodClass, NULL));
     652    = ((JArray<Method *> *) JvNewObjectArray (count,
     653                                              &Method::class$,
     654                                              NULL));
    620655
    621656  // When filling the array for real, we get the actual count.  Then
     
    626661    {
    627662      JArray<Method *> *r2
    628         = ((JArray<Method *> *) JvNewObjectArray (real_count, &MethodClass,
     663        = ((JArray<Method *> *) JvNewObjectArray (real_count,
     664                                                  &Method::class$,
    629665                                                  NULL));
    630666     
     
    666702  // FIXME: we special-case one check here just to pass a Plum Hall
    667703  // test.  Once access checking is implemented, remove this.
    668   if (this == &ClassClass)
     704  if (this == &)
    669705    throw new java::lang::IllegalAccessException;
    670706
     
    735771
    736772  // Steps 3 &  4.
    737   if (state == JV_STATE_DONE
    738       || state == JV_STATE_IN_PROGRESS
    739       || thread == self)
     773  if (state == JV_STATE_DONE || state == JV_STATE_IN_PROGRESS)
    740774    {
    741775      _Jv_MonitorExit (this);
     
    747781    {
    748782      _Jv_MonitorExit (this);
    749       throw new java::lang::NoClassDefFoundError;
     783      throw new java::lang::NoClassDefFoundError;
    750784    }
    751785
     
    783817  catch (java::lang::Throwable *except)
    784818    {
    785       if (! ErrorClass.isInstance(except))
     819      if (! .isInstance(except))
    786820        {
    787821          try
     
    876910                       _Jv_Method *method)
    877911{
    878   _Jv_MonitorEnter (&ClassClass);
     912  _Jv_MonitorEnter (&);
    879913
    880914  int index = method->name->hash & MCACHE_SIZE;
     
    883917  method_cache[index].klass = klass;
    884918
    885   _Jv_MonitorExit (&ClassClass);
     919  _Jv_MonitorExit (&);
    886920}
    887921
     
    933967  if (source == target)
    934968    return true;
    935      
     969
    936970  // If target is array, so must source be. 
    937   if (target->isArray ())
     971  (target->isArray ())
    938972    {
    939973      if (! source->isArray())
    940974        return false;
    941       return _Jv_IsAssignableFrom(target->getComponentType(),
    942                                   source->getComponentType());
     975     
     976      );
    943977    }
    944978
     
    950984          (source->idt == NULL || source->isInterface(), false))
    951985        return _Jv_InterfaceAssignableFrom (target, source);
    952        
     986
    953987      _Jv_IDispatchTable *cl_idt = source->idt;
    954988      _Jv_IDispatchTable *if_idt = target->idt;
     
    9661000      return false;
    9671001    }
    968      
     1002
    9691003  // Primitive TYPE classes are only assignable to themselves.
    970   if (__builtin_expect (target->isPrimitive(), false))
     1004  if (__builtin_expect (target->isPrimitive(), false))
    9711005    return false;
    972    
    973   if (target == &ObjectClass)
    974     {
    975       if (source->isPrimitive())
    976         return false;
    977       return true;
    978     }
    979   else if (source->ancestors != NULL
    980            && target->ancestors != NULL
    981            && source->depth >= target->depth
     1006
     1007  if (target == &java::lang::Object::class$)
     1008    return true;
     1009  else if (source->ancestors == NULL || target->ancestors == NULL)
     1010    {
     1011      // We need this case when either SOURCE or TARGET has not has
     1012      // its constant-time tables prepared.
     1013
     1014      // At this point we know that TARGET can't be Object, so it is
     1015      // safe to use that as the termination point.
     1016      while (source && source != &java::lang::Object::class$)
     1017        {
     1018          if (source == target)
     1019            return true;
     1020          source = source->getSuperclass();
     1021        }
     1022    }
     1023  else if (source->depth >= target->depth
    9821024           && source->ancestors[source->depth - target->depth] == target)
    9831025    return true;
    984      
     1026
    9851027  return false;
    9861028}
     
    10371079      JvAssert (arr != NULL);
    10381080      jclass elt_class = (JV_CLASS (arr))->getComponentType();
     1081
     1082
    10391083      jclass obj_class = JV_CLASS (obj);
    10401084      if (__builtin_expect
    10411085          (! _Jv_IsAssignableFrom (elt_class, obj_class), false))
    1042         throw new java::lang::ArrayStoreException;
     1086        throw new java::lang::ArrayStoreException
     1087                ((new java::lang::StringBuffer
     1088                 (JvNewStringUTF("Cannot store ")))->append
     1089                 (obj_class->getName())->append
     1090                 (JvNewStringUTF(" in array of type "))->append
     1091                 (elt_class->getName())->toString());
    10431092    }
    10441093}
     
    10711120  jclass klass0 = klass;
    10721121  jboolean has_interfaces = 0;
    1073   while (klass0 != &ObjectClass)
     1122  while (klass0 != &)
    10741123    {
    10751124      has_interfaces += klass0->interface_count;
     
    13141363
    13151364static _Jv_Mutex_t iindex_mutex;
    1316 bool iindex_mutex_initialized = false;
     1365bool iindex_mutex_initialized = false;
    13171366
    13181367// We need to find the correct offset in the Class Interface Dispatch
     
    15281577
    15291578// Returns true if METH should get an entry in a VTable.
    1530 static bool
     1579static
    15311580isVirtualMethod (_Jv_Method *meth)
    15321581{
     
    15341583  return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
    15351584          && meth->name->data[0] != '<');
     1585
     1586
     1587
     1588
     1589
     1590
     1591
    15361592}
    15371593
     
    15461602      || klass->vtable_method_count != -1)
    15471603    return;
    1548    
     1604
    15491605  jclass superclass = klass->superclass;
    15501606
     
    15541610      _Jv_LayoutVTableMethods (superclass);
    15551611    }
    1556    
     1612
    15571613  int index = (superclass == NULL ? 0 : superclass->vtable_method_count);
    15581614
     
    15611617      _Jv_Method *meth = &klass->methods[i];
    15621618      _Jv_Method *super_meth = NULL;
    1563    
    1564       if (!isVirtualMethod(meth))
    1565         continue;
    1566              
     1619
     1620      if (!(meth))
     1621continue;
     1622
    15671623      if (superclass != NULL)
    1568         super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name,
    1569                                                meth->signature);
    1570      
     1624        {
     1625          super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name,
     1626                                                 meth->signature);
     1627        }
     1628
    15711629      if (super_meth)
    15721630        meth->index = super_meth->index;
     1631
     1632
     1633
     1634
     1635
     1636
     1637
     1638
     1639
     1640
     1641
     1642
     1643
     1644
     1645
     1646
     1647
     1648
     1649
     1650
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
    15731662      else
    1574         meth->index = index++;
    1575     }
    1576  
    1577   klass->vtable_method_count = index;
    1578 }
    1579 
    1580 // Set entries in VTABLE for virtual methods declared in KLASS. If KLASS has
    1581 // an immediate abstract parent, recursivly do its methods first.
    1582 void
    1583 _Jv_SetVTableEntries (jclass klass, _Jv_VTable *vtable)
    1584 {
    1585   using namespace java::lang::reflect;
    1586 
    1587   jclass superclass = klass->getSuperclass();
    1588 
    1589   if (superclass != NULL && (superclass->getModifiers() & Modifier::ABSTRACT))
    1590     _Jv_SetVTableEntries (superclass, vtable);
    1591    
    1592   for (int i = klass->method_count - 1; i >= 0; i--)
    1593     {
    1594       _Jv_Method *meth = &klass->methods[i];
    1595       if (!isVirtualMethod(meth))
    1596         continue;
    1597       vtable->set_method(meth->index, meth->ncode);
     1663        {
     1664          vtable->set_method(meth->index, meth->ncode);
     1665          flags[meth->index] = true;
     1666        }
    15981667    }
    15991668}
     
    16111680      || (klass->accflags & Modifier::ABSTRACT))
    16121681    return;
    1613  
     1682
    16141683  //  out before we can create a vtable.
    16151684  if (klass->vtable_method_count == -1)
     
    16191688  _Jv_VTable *vtable = _Jv_VTable::new_vtable (klass->vtable_method_count);
    16201689  klass->vtable = vtable;
    1621  
     1690
     1691  jboolean flags[klass->vtable_method_count];
     1692  for (int i = 0; i < klass->vtable_method_count; ++i)
     1693    flags[i] = false;
     1694
    16221695  // Copy the vtable of the closest non-abstract superclass.
    16231696  jclass superclass = klass->superclass;
     
    16341707
    16351708      for (int i = 0; i < superclass->vtable_method_count; ++i)
    1636         vtable->set_method (i, superclass->vtable->get_method (i));
     1709        {
     1710          vtable->set_method (i, superclass->vtable->get_method (i));
     1711          flags[i] = true;
     1712        }
    16371713    }
    16381714
     
    16431719  // For each virtual declared in klass and any immediate abstract
    16441720  // superclasses, set new vtable entry or override an old one.
    1645   _Jv_SetVTableEntries (klass, vtable);
    1646 }
     1721  _Jv_SetVTableEntries (klass, vtable, flags);
     1722
     1723  // It is an error to have an abstract method in a concrete class.
     1724  if (! (klass->accflags & Modifier::ABSTRACT))
     1725    {
     1726      for (int i = 0; i < klass->vtable_method_count; ++i)
     1727        if (! flags[i])
     1728          // FIXME: messsage.
     1729          throw new java::lang::AbstractMethodError ();
     1730    }
     1731}
Note: See TracChangeset for help on using the changeset viewer.