示例#1
0
    @Override
    public void setValue(VirtualFrame frame, PythonObject primary, Object value) {
      if (!primary.getStableAssumption().isValid()) {
        primary.syncObjectLayoutWithClass();
      }

      primary.setAttribute(attributeId, value);
    }
示例#2
0
    @Override
    public void setValue(VirtualFrame frame, PythonObject primary, Object value) {
      CompilerDirectives.transferToInterpreterAndInvalidate();
      assert primary.verifyLayout();

      if (!primary.getStableAssumption().isValid()) {
        primary.syncObjectLayoutWithClass();
      }

      assert primary.verifyLayout();
      SetDispatchNode current = this;
      int depth = 0;

      while (current.getParent() instanceof SetDispatchNode) {
        current = (SetDispatchNode) current.getParent();
        depth++;

        if (!(current instanceof LinkedSetDispatchNode)) {
          continue;
        }

        /**
         * After the layout sync, if a previously missed dispatch node caches the updated layout, we
         * should reuse the existing dispatch node.
         */
        LinkedSetDispatchNode linked = (LinkedSetDispatchNode) current;
        try {
          if (linked.check.accept(primary)) {
            linked.setValue(frame, primary, value);
            return;
          }
        } catch (InvalidAssumptionException e) {
          throw new RuntimeException();
        }
      }

      if (depth < PythonOptions.AttributeAccessInlineCacheMaxDepth) {
        primary.setAttribute(attributeId, value);
        StorageLocation location = primary.getOwnValidLocation(attributeId);
        replace(
            new LinkedSetDispatchNode(
                attributeId, AttributeWriteNode.create(location), primary, this));
      } else {
        replace(new GenericSetDispatchNode(attributeId)).setValue(frame, primary, value);
      }
    }