コード例 #1
0
static void iterate_fields(InstanceClass* ic, OopVisitor* visitor, 
                           bool visit_value) {
  InstanceClass s = ic->super();
  // Print fields defined by super class
  if (!s.is_null()) {
    iterate_fields(&s, visitor, visit_value);
  }
  // Print fields define by local class
  TypeArray fields = ic->original_fields(); 
  int last_field_offset = -1;
  for (;;) {
    int next_field_index = -1;
    int min_offset = 0x7fffffff;

    for(int index = 0; index < fields.length(); index += 5) {
      OriginalField f(ic, index);
      if (!f.is_static() &&
          f.offset() > last_field_offset && 
          f.offset() < min_offset) {
        next_field_index = index;
        min_offset = f.offset();
      }
    }

    last_field_offset = min_offset;
    if (next_field_index < 0) {
      break;
    }

    OriginalField f(ic, next_field_index);
    Symbol name = f.name();
    SymbolField field(&name, false);
    switch(f.type()) {
    case T_BOOLEAN:
      visitor->do_bool(&field, f.offset(), visit_value);
      break;
    case T_CHAR:
      visitor->do_char(&field, f.offset(), visit_value);
      break;
    case T_FLOAT :
      visitor->do_float(&field, f.offset(), visit_value);
      break;
    case T_DOUBLE:
      visitor->do_double(&field, f.offset(), visit_value);
      break;
    case T_BYTE:
      visitor->do_byte(&field, f.offset(), visit_value);
      break;
    case T_SHORT:
      visitor->do_short(&field, f.offset(), visit_value);
      break;
    case T_INT:
      visitor->do_int(&field, f.offset(), visit_value);
      break;
    case T_LONG:
      visitor->do_long(&field, f.offset(), visit_value);
      break;
    case T_OBJECT:
      visitor->do_oop(&field, f.offset(), visit_value);
      break;
    case T_ARRAY:
      visitor->do_oop(&field, f.offset(), visit_value);
      break;
    }
  }
}
コード例 #2
0
ファイル: CompilerTest.cpp プロジェクト: sfsy1989/j2me
ReturnOop CompilerTest::load_and_sort_classes(JVM_SINGLE_ARG_TRAPS) {
  UsingFastOops fast_oops;
  ObjArray::Fast classes;
  JavaClass::Fast klass;
  int num_system_classes = 0;

  ObjArray::Fast classpath = Task::current()->app_classpath();
  for (int index = 0; index < classpath().length(); index++) {
    FilePath path = classpath().obj_at(index);
    Universe::load_all_in_classpath_segment(&path JVM_CHECK_0);
    if (!UseROM && num_system_classes == 0) {
      // If the system classes are not romized, we consider the first
      // segment of the classpath to contain the system classes. So do this:
      //    -classpath classes.zip:mytest.zip
      // instead of this:
      //    -classpath mytest.zip:classes.zip
      num_system_classes = Universe::number_of_java_classes();
    }
  }

  int num = 0;
  int added = 0;

  // (1) Find all the classes in the classpath (and optionally the system
  //     classes as well).
  for (int pass=0; pass<2; pass++) {
    for (int i=0; i< Universe::number_of_java_classes(); i++) {
      klass = Universe::class_from_id(i);
      if (klass().is_array_class() || klass().is_fake_class()) {
        continue;
      }
      if (!TestCompileSystemClasses) {
        if (klass().is_preloaded()) {
          continue;
        }
        if (!UseROM && i < num_system_classes) {
          continue;
        }
      }
      if (pass == 0) {
        num ++;
      } else {
        classes().obj_at_put(added++, &klass);
      }
    }

    if (pass == 0) {
      classes = Universe::new_obj_array(num JVM_CHECK_0);
    }
  }

  // (2) Sort the list
  int i, j;
  for (i=0; i<num; i++) {
    for (j=i; j<num; j++) {
      InstanceClass::Raw ci = classes().obj_at(i);
      InstanceClass::Raw cj = classes().obj_at(j);
      if (compare(&ci, &cj) > 0) {
        classes().obj_at_put(i, &cj);
        classes().obj_at_put(j, &ci);
      }
    }
  }

#if 0
  // (3) Set all classes to be initialized, so that we won't generate any
  //     uncommon traps. This yields stable results and is close to what
  //     happens in real execution.
  for (i=0; i<num; i++) {
    UsingFastOops fast_oops_inside;
    InstanceClass::Fast ic = classes().obj_at(i);
    if (!ic().is_romized()) {
      ic().set_initialized();
    }
  }
#else
  // (3) Initialize all classes, so that we won't generate any
  //     uncommon traps. This yields stable results and is close to what
  //     happens in real execution.

  for (;;) {
    bool made_progress = false;
    for (i=0; i< Universe::number_of_java_classes(); i++) {
      klass = Universe::class_from_id(i);
      if (klass().is_array_class() || klass().is_fake_class()) {
        continue;
      }
      InstanceClass ic = klass.obj();
      if (may_be_initialized(&ic)) {
        made_progress = true;
        ic.initialize(JVM_SINGLE_ARG_CHECK_0);
      }
      Universe::invoke_pending_entries(JVM_SINGLE_ARG_CHECK_0);
    }

    if (!made_progress) {
      // We have initialized all classes that may be initialized
      break;
    }
  }
#endif

  return classes;
}
コード例 #3
0
void Instance::print_value_on(Stream* st) {
  st->print("an instance of class ");
  InstanceClass ic = blueprint();
  ic.print_name_on(st);
}