void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig,
                                 KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class,
                                 TRAPS) {
  assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
         byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
         (byte == Bytecodes::_nop && !check_access), "bad field access bytecode");

  bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
  bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic);

  // Check if there's a resolved klass containing the field
  if (resolved_klass.is_null()) {
    ResourceMark rm(THREAD);
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  }

  // Resolve instance field
  KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
  // check if field exists; i.e., if a klass containing the field def has been selected
  if (sel_klass.is_null()) {
    ResourceMark rm(THREAD);
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  }

  // Access checking may be turned off when calling from within the VM.
  if (check_access) {

    // check access
    check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);

    // check for errors
    if (is_static != fd.is_static()) {
      ResourceMark rm(THREAD);
      char msg[200];
      jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string());
      THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
    }

    // Final fields can only be accessed from its own class.
    if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
      THROW(vmSymbols::java_lang_IllegalAccessError());
    }

    // initialize resolved_klass if necessary
    // note 1: the klass which declared the field must be initialized (i.e, sel_klass)
    //         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)
    //
    // note 2: we don't want to force initialization if we are just checking
    //         if the field access is legal; e.g., during compilation
    if (is_static && initialize_class) {
      sel_klass->initialize(CHECK);
    }
  }

  if (sel_klass() != current_klass() && !current_klass.is_null()) {
    HandleMark hm(THREAD);
    Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());
    Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());
    {
      ResourceMark rm(THREAD);
      Symbol* failed_type_symbol =
        SystemDictionary::check_signature_loaders(sig,
                                                  ref_loader, sel_loader,
                                                  false,
                                                  CHECK);
      if (failed_type_symbol != NULL) {
        const char* msg = "loader constraint violation: when resolving field"
          " \"%s\" the class loader (instance of %s) of the referring class, "
          "%s, and the class loader (instance of %s) for the field's resolved "
          "type, %s, have different Class objects for that type";
        char* field_name = field->as_C_string();
        const char* loader1 = SystemDictionary::loader_name(ref_loader());
        char* sel = InstanceKlass::cast(sel_klass())->name()->as_C_string();
        const char* loader2 = SystemDictionary::loader_name(sel_loader());
        char* failed_type_name = failed_type_symbol->as_C_string();
        size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) +
          strlen(sel) + strlen(loader2) + strlen(failed_type_name) + 1;
        char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
        jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2,
                     failed_type_name);
        THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
      }
    }
  }

  // return information. note that the klass is set to the actual klass containing the
  // field, otherwise access of static fields in superclasses will not work.
}
void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig,
                                 KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class,
                                 TRAPS) {
  assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
         byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
         (byte == Bytecodes::_nop && !check_access), "bad field access bytecode");

  bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
  bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic);

   
  if (resolved_klass.is_null()) {
    ResourceMark rm(THREAD);
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  }

   
  KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
   
  if (sel_klass.is_null()) {
    ResourceMark rm(THREAD);
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  }

   
  if (check_access) {

     
    check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);

     
    if (is_static != fd.is_static()) {
      ResourceMark rm(THREAD);
      char msg[200];
      jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string());
      THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
    }

     
    if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
      THROW(vmSymbols::java_lang_IllegalAccessError());
    }

     
     
     
     
     
     
    if (is_static && initialize_class) {
      sel_klass->initialize(CHECK);
    }
  }

  if (sel_klass() != current_klass() && !current_klass.is_null()) {
    HandleMark hm(THREAD);
    Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());
    Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());
    {
      ResourceMark rm(THREAD);
      Symbol* failed_type_symbol =
        SystemDictionary::check_signature_loaders(sig,
                                                  ref_loader, sel_loader,
                                                  false,
                                                  CHECK);
      if (failed_type_symbol != NULL) {
        const char* msg = "loader constraint violation: when resolving field"
          " \"%s\" the class loader (instance of %s) of the referring class, "
          "%s, and the class loader (instance of %s) for the field's resolved "
          "type, %s, have different Class objects for that type";
        char* field_name = field->as_C_string();
        const char* loader1 = SystemDictionary::loader_name(ref_loader());
        char* sel = InstanceKlass::cast(sel_klass())->name()->as_C_string();
        const char* loader2 = SystemDictionary::loader_name(sel_loader());
        char* failed_type_name = failed_type_symbol->as_C_string();
        size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) +
          strlen(sel) + strlen(loader2) + strlen(failed_type_name) + 1;
        char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
        jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2,
                     failed_type_name);
        THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
      }
    }
  }

   
   
}