Esempio n. 1
0
  VMMethod* CompiledMethod::internalize(STATE, GCToken gct,
                                        const char** reason, int* ip)
  {
    VMMethod* vmm = backend_method_;

    atomic::memory_barrier();

    if(vmm) return vmm;

    CompiledMethod* self = this;
    OnStack<1> os(state, self);

    self->hard_lock(state, gct);

    vmm = self->backend_method_;
    if(!vmm) {
      {
        BytecodeVerification bv(self);
        if(!bv.verify(state)) {
          if(reason) *reason = bv.failure_reason();
          if(ip) *ip = bv.failure_ip();
          std::cerr << "Error validating bytecode: " << bv.failure_reason() << "\n";
          return 0;
        }
      }

      vmm = new VMMethod(state, self);

      if(self->resolve_primitive(state)) {
        vmm->fallback = execute;
      } else {
        vmm->setup_argument_handler(self);
      }

      // We need to have an explicit memory barrier here, because we need to
      // be sure that vmm is completely initialized before it's set.
      // Otherwise another thread might see a partially initialized
      // VMMethod.
      atomic::memory_barrier();
      backend_method_ = vmm;
    }

    self->hard_unlock(state, gct);
    return vmm;
  }