also used by DoublesSketch, DoublesUnionImpl and HeapDoublesSketchTest
7523
static void downSamplingMergeInto(final DoublesSketch src, final UpdateDoublesSketch tgt) {
    final int srcK = src.getK();
    final int tgtK = tgt.getK();
    final long tgtN = tgt.getN();

    if ((srcK % tgtK) != 0) {
      throw new SketchesArgumentException(
          "source.getK() must equal target.getK() * 2^(nonnegative integer).");
    }

    final int downFactor = srcK / tgtK;
    checkIfPowerOf2(downFactor, "source.getK()/target.getK() ratio");
    final int lgDownFactor = Integer.numberOfTrailingZeros(downFactor);

    if (src.isEmpty()) { return; }

    final DoublesSketchAccessor srcSketchBuf = DoublesSketchAccessor.wrap(src);
    final long nFinal = tgtN + src.getN();

    for (int i = 0; i < srcSketchBuf.numItems(); i++) { // update only the base buffer
      tgt.update(srcSketchBuf.get(i));
    }

    final int spaceNeeded = DoublesUpdateImpl.getRequiredItemCapacity(tgtK, nFinal);
    final int curCombBufCap = tgt.getCombinedBufferItemCapacity();
    if (spaceNeeded > curCombBufCap) { //copies base buffer plus current levels
      tgt.growCombinedBuffer(curCombBufCap, spaceNeeded);
    }

    //working scratch buffers
    final DoublesArrayAccessor scratch2KAcc = DoublesArrayAccessor.initialize(2 * tgtK);
    final DoublesArrayAccessor downScratchKAcc = DoublesArrayAccessor.initialize(tgtK);

    final DoublesSketchAccessor tgtSketchBuf = DoublesSketchAccessor.wrap(tgt, true);

    long srcBitPattern = src.getBitPattern();
    long newTgtBitPattern = tgt.getBitPattern();
    for (int srcLvl = 0; srcBitPattern != 0L; srcLvl++, srcBitPattern >>>= 1) {
      if ((srcBitPattern & 1L) > 0L) {
        justZipWithStride(
                srcSketchBuf.setLevel(srcLvl),
                downScratchKAcc,
                tgtK,
                downFactor
        );
        newTgtBitPattern = DoublesUpdateImpl.inPlacePropagateCarry(
                srcLvl + lgDownFactor,    //starting level
                downScratchKAcc,       //optSrcKBuf,
                scratch2KAcc,          //size2KBuf,
                false,                    //do mergeInto version
                tgtK,
                tgtSketchBuf,
                newTgtBitPattern
        );

        tgt.putBitPattern(newTgtBitPattern); //off-heap is a no-op
      }
    }
    if (tgt.isDirect() && (nFinal > 0)) {
      final WritableMemory mem = tgt.getMemory();
      mem.clearBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK);
    }
    tgt.putN(nFinal);

    assert (tgt.getN() / (2L * tgtK)) == newTgtBitPattern; // internal consistency check

    double srcMax = src.getMaxValue();
    srcMax = Double.isNaN(srcMax) ? Double.NEGATIVE_INFINITY : srcMax;
    double srcMin = src.getMinValue();
    srcMin = Double.isNaN(srcMin) ? Double.POSITIVE_INFINITY : srcMin;

    double tgtMax = tgt.getMaxValue();
    tgtMax = Double.isNaN(tgtMax) ? Double.NEGATIVE_INFINITY : tgtMax;
    double tgtMin = tgt.getMinValue();
    tgtMin = Double.isNaN(tgtMin) ? Double.POSITIVE_INFINITY : tgtMin;

    if (srcMax > tgtMax) { tgt.putMaxValue(srcMax); }
    if (srcMin < tgtMin) { tgt.putMinValue(srcMin); }
  }
333821
void write(ByteCodeWriter out)
    throws IOException
  {
    out.write(ConstantPool.CP_DOUBLE);
    out.writeDouble(_value);
  }
425071
@Nullable
  private static Symbol tryGetSymbol(Tree tree) {
    if (tree instanceof JCIdent) {
      return ((JCIdent) tree).sym;
    }
    if (tree instanceof JCFieldAccess) {
      return ((JCFieldAccess) tree).sym;
    }
    if (tree instanceof JCVariableDecl) {
      return ((JCVariableDecl) tree).sym;
    }
    return null;
  }
637715
double run_benchmark() {
    // use the lesser of 40MB or 10% of Heap
    final long M = Math.min(10000000l, Runtime.getRuntime().maxMemory()/40);
    int[] vals = MemoryManager.malloc4((int)M);
    double total;
    int repeats = 20;
    Timer timer = new Timer(); //ms
    long sum = 0;
    // write repeats * M ints
    // read  repeats * M ints
    for (int l=repeats-1; l>=0; --l) {
      for (int i=0; i<M; ++i) {
        vals[i] = i + l;
      }
      sum = 0;
      for (int i=0; i<M; ++i) {
        sum += vals[i];
      }
    }
    total = (double)timer.time()/1000./repeats;
    //use the sum in a way that doesn't affect the result (don't want the compiler to optimize it away)
    double time = total + ((M*(M-1)/2) - sum); // == total
    return (double)2*M*4/time; //(read+write) * 4 bytes
  }
1349846
@Override
  public void aggregate(final ByteBuffer buf, final int position)
  {
    for (int i = 0; i < valueSelectors.length; i++) {
      values[i] = valueSelectors[i].getDouble();
    }
    final IndexedInts keys = keySelector.getRow();
    // Wrapping memory and ArrayOfDoublesSketch is inexpensive compared to sketch operations.
    // Maintaining a cache of wrapped objects per buffer position like in Theta sketch aggregator
    // might might be considered, but it would increase complexity including relocate() support.
    final WritableMemory mem = WritableMemory.wrap(buf, ByteOrder.LITTLE_ENDIAN);
    final WritableMemory region = mem.writableRegion(position, maxIntermediateSize);
    final Lock lock = stripedLock.getAt(lockIndex(position)).writeLock();
    lock.lock();
    try {
      final ArrayOfDoublesUpdatableSketch sketch = ArrayOfDoublesSketches.wrapUpdatableSketch(region);
      for (int i = 0, keysSize = keys.size(); i < keysSize; i++) {
        final String key = keySelector.lookupName(keys.get(i));
        sketch.update(key, values);
      }
    }
    finally {
      lock.unlock();
    }
  }
1150256
void genCatch(JCCatch tree,
                      Env<GenContext> env,
                      int startpc, int endpc,
                      List<Integer> gaps) {
            if (startpc != endpc) {
                List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypeExprs
                        = catchTypesWithAnnotations(tree);
                while (gaps.nonEmpty()) {
                    for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) {
                        JCExpression subCatch = subCatch1.snd;
                        int catchType = makeRef(tree.pos(), subCatch.type);
                        int end = gaps.head.intValue();
                        registerCatch(tree.pos(),
                                      startpc,  end, code.curCP(),
                                      catchType);
                        for (Attribute.TypeCompound tc :  subCatch1.fst) {
                                tc.position.setCatchInfo(catchType, startpc);
                        }
                    }
                    gaps = gaps.tail;
                    startpc = gaps.head.intValue();
                    gaps = gaps.tail;
                }
                if (startpc < endpc) {
                    for (Pair<List<Attribute.TypeCompound>, JCExpression> subCatch1 : catchTypeExprs) {
                        JCExpression subCatch = subCatch1.snd;
                        int catchType = makeRef(tree.pos(), subCatch.type);
                        registerCatch(tree.pos(),
                                      startpc, endpc, code.curCP(),
                                      catchType);
                        for (Attribute.TypeCompound tc :  subCatch1.fst) {
                            tc.position.setCatchInfo(catchType, startpc);
                        }
                    }
                }
                VarSymbol exparam = tree.param.sym;
                code.statBegin(tree.pos);
                code.markStatBegin();
                int limit = code.nextreg;
                code.newLocal(exparam);
                items.makeLocalItem(exparam).store();
                code.statBegin(TreeInfo.firstStatPos(tree.body));
                genStat(tree.body, env, CRT_BLOCK);
                code.endScopes(limit);
                code.statBegin(TreeInfo.endPos(tree.body));
            }
        }
895315
@Override
  public Void visitCompilationUnit(CompilationUnitTree unit, Void unused) {
    scan(unit.getImports(), null);
    scan(unit.getPackageAnnotations(), null);
    scan(unit.getTypeDecls(), null);
    return null;
  }
106637
@Override
    protected boolean isAfter(int x, int y, Rectangle innerAlloc)
    {
        // System.err.println("isAfter: " + innerAlloc + " my bounds " +
        // box.getAbsoluteBounds());
        // System.err.println("XY: " + x + " : " + y);
        innerAlloc.setBounds(box.getAbsoluteBounds());
        if (majorAxis == View.X_AXIS)
        {
            return (x > (innerAlloc.width + innerAlloc.x));
        }
        else
        {
            return (y > (innerAlloc.height + innerAlloc.y));
        }
    }
1219062
static CompactSketch heapifyInstance(final Memory srcMem, final long seed) {
    final short memSeedHash = (short) extractSeedHash(srcMem);
    final short computedSeedHash = computeSeedHash(seed);
    checkSeedHashes(memSeedHash, computedSeedHash);

    final int preLongs = extractPreLongs(srcMem);
    final boolean empty = PreambleUtil.isEmpty(srcMem);
    int curCount = 0;
    long thetaLong = Long.MAX_VALUE;
    long[] cache = new long[0];

    if (preLongs == 1) {
      if (!empty) { //singleItem
        return new SingleItemSketch(srcMem.getLong(8), memSeedHash);
      }
      //else empty
    } else { //preLongs > 1
      curCount = extractCurCount(srcMem);
      cache = new long[curCount];
      if (preLongs == 2) {
        srcMem.getLongArray(16, cache, 0, curCount);
      } else { //preLongs == 3
        srcMem.getLongArray(24, cache, 0, curCount);
        thetaLong = extractThetaLong(srcMem);
      }
    }
    return new HeapCompactOrderedSketch(cache, empty, memSeedHash, curCount, thetaLong);
  }
1322783
@FFDCIgnore(IllegalArgumentException.class)
    private List<String> evaluateHashAlgorithmParameters() {
        List<String> parameters = new ArrayList<String>();

        String[] rawArray = idStoreDefinition.hashAlgorithmParameters();
        if (rawArray == null || rawArray.length == 0) {
            return parameters;
        }

        /*
         * The EL expressions is used for a full array element. It must evaluate to either a
         * single string, a string array or string Stream.
         */
        if (rawArray.length == 1) {
            /*
             * Process as String.
             */
            try {
                String value = elHelper.processString("hashAlgorithmParameters[0]", rawArray[0], false);
                if (value != null && !value.isEmpty()) {
                    parameters.add(value);
                }
                return parameters;
            } catch (IllegalArgumentException e) {
                // Ignore.
            }

            /*
             * Process as String[].
             */
            try {
                String[] array = elHelper.processStringArray("hashAlgorithmParameters[0]", rawArray[0], false, false);
                if (array != null && array.length == 0) {
                    for (String value : array) {
                        if (value != null && !value.isEmpty()) {
                            parameters.add(value);
                        }
                    }
                }
                return parameters;
            } catch (IllegalArgumentException e) {
                // Ignore.
            }

            /*
             * Process as Stream<String>.
             */
            try {
                Stream<String> stream = elHelper.processStringStream("hashAlgorithmParameters[0]", rawArray[0], false, false);
                Iterator<String> iterator = stream.iterator();
                while (iterator.hasNext()) {
                    String value = iterator.next();
                    if (value != null && !value.isEmpty()) {
                        parameters.add(value);
                    }
                }
                return parameters;
            } catch (IllegalArgumentException e) {
                // Ignore.
            }

            if (TraceComponent.isAnyTracingEnabled() && tc.isWarningEnabled()) {
                Tr.warning(tc, "JAVAEESEC_WARNING_IDSTORE_CONFIG", new Object[] { "hashAlgorithmParameters[0]", Collections.emptyList() });
            }
        } else {
            if (rawArray != null && rawArray.length > 0) {
                for (int idx = 0; idx < rawArray.length; idx++) {
                    String value = elHelper.processString("hashAlgorithmParameters[" + idx + "]", rawArray[idx], false);
                    if (value != null && !value.isEmpty()) {
                        parameters.add(value);
                    }
                }
            }
        }

        return parameters;
    }
257348
static final Memory loadCompactMemory(final long[] compactCache, final short seedHash,
      final int curCount, final long thetaLong, final WritableMemory dstMem,
      final byte flags, final int preLongs) {

    assert (dstMem != null) && (compactCache != null);
    final int outLongs = preLongs + curCount;
    final int outBytes = outLongs << 3;
    final int dstBytes = (int) dstMem.getCapacity();
    if (outBytes > dstBytes) {
      throw new SketchesArgumentException("Insufficient Memory: " + dstBytes
        + ", Need: " + outBytes);
    }
    final byte famID = (byte) Family.COMPACT.getID();

    insertPreLongs(dstMem, preLongs); //RF not used = 0
    insertSerVer(dstMem, SER_VER);
    insertFamilyID(dstMem, famID);
    //ignore lgNomLongs, lgArrLongs bytes for compact sketches
    insertFlags(dstMem, flags);
    insertSeedHash(dstMem, seedHash);

    if ((preLongs == 1) && (curCount == 1)) { //singleItem
      dstMem.putLong(8, compactCache[0]);
      return dstMem;
    }
    if (preLongs > 1) {
      insertCurCount(dstMem, curCount);
      insertP(dstMem, (float) 1.0);
    }
    if (preLongs > 2) {
      insertThetaLong(dstMem, thetaLong);
    }
    if (curCount > 0) {
      dstMem.putLongArray(preLongs << 3, compactCache, 0, curCount);
    }
    return dstMem;
  }
457163
function heapUsageP(heapData, options) {
        return co(_heap, heapData, options);

        /**
         * 内部处理逻辑
         */
        function* _heap(heapData, options) {
            options = options || {};

            const rootIndex = heapData.snapshot.root_index || 0;
            let jsHeapSnapShot = yield heapSnapShotCalculateP(heapData, options);
            let leakPoint = peakLeakPoint(jsHeapSnapShot, rootIndex, options.limit);

            return { leakPoint, jsHeapSnapShot, rootIndex };
        }
    }
93847
public static DoubleAD logSum(DoubleAD[] logInputs, int fromIndex, int toIndex) {
    if (logInputs.length == 0)
      throw new IllegalArgumentException();
    if(fromIndex >= 0 && toIndex < logInputs.length && fromIndex >= toIndex)
      return new DoubleAD(Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY);
    int maxIdx = fromIndex;
    double max = logInputs[fromIndex].getval();
    double maxdot = logInputs[fromIndex].getdot();

    for (int i = fromIndex+1; i < toIndex; i++) {
      if (logInputs[i].getval() > max) {
        maxIdx = i;
        maxdot = logInputs[i].getdot();
        max = logInputs[i].getval();
      }
    }

    DoubleAD ret = new DoubleAD();
    boolean haveTerms = false;
    double intermediate = 0.0;
    double intermediateDot = 0.0;
    double curEXP;
    double cutoff = max - SloppyMath.LOGTOLERANCE;
    // we avoid rearranging the array and so test indices each time!
    for (int i = fromIndex; i < toIndex; i++) {
      if (i != maxIdx && logInputs[i].getval() > cutoff) {
        haveTerms = true;
        curEXP = Math.exp(logInputs[i].getval() - max);
        intermediate += curEXP;
        intermediateDot += curEXP*logInputs[i].getdot();
      }
    }
    if (haveTerms) {
      ret.setval(max + Math.log(1.0 + intermediate));
      ret.setdot((maxdot + intermediateDot)/(1.0 + intermediate));
    } else {
      ret.setval(max);
      ret.setdot(maxdot);
    }
      return ret;
  }
852560
void handlePut(
    SimpleTest test,
    Conjunction selector,
    MatchTarget object,
    InternTable subExpr)
    throws MatchingException
  {
    if (tc.isEntryEnabled())
      tc.entry(
        this,
        cclass,
        "handlePut",
        new Object[] { test, selector, object, subExpr });
    Object value = test.getValue();
    if (value != null)
      handleEqualityPut(value, selector, object, subExpr);
    else {
      Pattern pattern = ((LikeOperatorImpl) test.getTests()[0]).getInternalPattern();
      subTree.put(new PatternWrapper(pattern), selector, object, subExpr);
    }

    if (tc.isEntryEnabled())
      tc.exit(this,cclass, "handlePut");
  }
164499
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> mapDoubles(DoubleUnaryOperator b){

        return a->a.doubles(i->i,s->s.map(b));
    }
882406
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> skipDoubles(long skip){

        return a->a.doubles(i->i,s->s.skip(skip));
    }
1345501
private static Spliterator.OfDouble adapt(Spliterator<Double> s) {
        if (s instanceof Spliterator.OfDouble) {
            return (Spliterator.OfDouble) s;
        } else {
//            if (Tripwire.ENABLED)
//                Tripwire.trip(AbstractPipeline.class,
//                              "using DoubleStream.adapt(Spliterator<Double> s)");
            throw new UnsupportedOperationException("DoubleStream.adapt(Spliterator<Double> s)");
        }
    }