Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.oracle.truffle.api.object;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.Equivalence;
import org.graalvm.collections.Pair;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Idempotent;
import com.oracle.truffle.api.dsl.NonIdempotent;
/**
* A Shape is an immutable descriptor of the current object "shape" of a DynamicObject, i.e., object
* layout, metadata ({@linkplain Shape#getDynamicType() type}, {@linkplain Shape#getFlags() flags}),
* and a mapping of {@linkplain Property properties} to storage locations. This allows cached
* {@link DynamicObjectLibrary} to do a simple shape check to determine the contents of an object
* and do fast, constant-time property accesses.
*
*
* Shapes are shared between objects that assume the same shape if they follow the same shape
* transitions, like adding the same properties in the same order, starting from a common root
* shape. Shape transitions are automatically, weakly cached.
*
*
* Dynamic objects start off with an initial shape that has no instance properties (but may have
* constant properties that are stored in the shape). Initial shapes are created via
* {@link Shape#newBuilder()}.
*
* @see DynamicObject
* @see Shape#newBuilder()
* @see Property
* @since 0.8 or earlier
*/
public abstract class Shape {
static final int OBJECT_FLAGS_MASK = 0x0000_ffff;
static final int OBJECT_FLAGS_SHIFT = 0;
static final int OBJECT_SHARED = 1 << 16;
static final int OBJECT_PROPERTY_ASSUMPTIONS = 1 << 17;
// keep in sync with Flags.java
static final int PUT_CONSTANT = 1 << 5;
/**
* Creates a new initial shape builder.
*
*
* The builder instance is not thread-safe and must not be used from multiple threads at the
* same time.
*
* @since 20.2.0
*/
public static Builder newBuilder() {
CompilerAsserts.neverPartOfCompilation();
return new Builder();
}
/**
* Internal superclass shared by {@link Builder} and {@link DerivedBuilder}.
*
* @since 20.2.0
*/
abstract static class AbstractBuilder> {
/**
* Sets initial dynamic object type identifier.
*
* See {@link DynamicObjectLibrary#setDynamicType(DynamicObject, Object)} for more
* information.
*
* @param dynamicType a non-null object type identifier
* @throws NullPointerException if the type is {@code null}
* @since 20.2.0
*/
public abstract T dynamicType(Object dynamicType);
/**
* Sets initial shape flags (default: 0). Currently limited to 16 bits.
*
* See {@link DynamicObjectLibrary#setShapeFlags(DynamicObject, int)} for more information.
*
* @param flags an int value in the range from 0 to 65535 (inclusive)
* @throws IllegalArgumentException if the flags value is not in the supported range
* @since 20.2.0
*/
public abstract T shapeFlags(int flags);
/**
* Adds a property with a constant value to the shape. The key must not be {@code null} and
* must not be equal to any previously added property's key.
*
* @param key the property's key
* @param value the property's value
* @param flags the property's flags
* @throws NullPointerException if the key is {@code null}
* @throws IllegalArgumentException if a property with the key already exists
* @see DynamicObjectLibrary#putConstant(DynamicObject, Object, Object, int)
* @since 20.2.0
*/
public abstract T addConstantProperty(Object key, Object value, int flags);
static Object checkDynamicType(Object dynamicType) {
Objects.requireNonNull(dynamicType, "dynamicType");
return dynamicType;
}
static int checkShapeFlags(int flags) {
if ((flags & ~OBJECT_FLAGS_MASK) != 0) {
throw new IllegalArgumentException("flags must be in the range [0, 0xffff]");
}
return flags;
}
}
/**
* Builder class to construct initial {@link Shape} instances.
*
* The builder instance is not thread-safe and must not be used from multiple threads at the
* same time.
*
* @see Shape#newBuilder()
* @since 20.2.0
*/
@SuppressWarnings({"hiding", "deprecation"})
public static final class Builder extends AbstractBuilder {
private Class extends DynamicObject> layoutClass = DynamicObject.class;
private Object dynamicType = ObjectType.DEFAULT;
private int shapeFlags;
private boolean allowImplicitCastIntToDouble;
private boolean allowImplicitCastIntToLong;
private boolean shared;
private boolean propertyAssumptions;
private Object sharedData;
private Assumption singleContextAssumption;
private EconomicMap