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) 2013, 2024 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 2.0, or
* GNU General Public License version 2, or
* GNU Lesser General Public License version 2.1.
*/
package org.truffleruby.core;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.time.Duration;
import java.util.Arrays;
import com.oracle.truffle.api.TruffleSafepoint;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.strings.TruffleString;
import org.truffleruby.annotations.SuppressFBWarnings;
import org.truffleruby.annotations.CoreMethod;
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
import org.truffleruby.annotations.CoreModule;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import org.truffleruby.annotations.Primitive;
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
import org.truffleruby.collections.WeakValueCache;
import org.truffleruby.core.array.RubyArray;
import org.truffleruby.core.encoding.Encodings;
import org.truffleruby.language.control.RaiseException;
@CoreModule("GC")
public abstract class GCNodes {
@Primitive(name = "gc_start")
public abstract static class GCStartPrimitiveNode extends PrimitiveArrayArgumentsNode {
@TruffleBoundary
@Specialization
Object vmGCStart() {
System.gc();
return nil;
}
}
/** Attempts to run the garbage collector. This cannot be guaranteed in general, but calling this method should be
* much more likely to actually trigger GC than calling {@link System#gc()} or Ruby's {@link GCStartPrimitiveNode}.
*
*
* In particular, this attempts to trigger the GC by waiting until a weak reference has been cleared.
*
*
* Note that even when GC is triggered, there is not guarantee that the all the garbage has been cleared or all the
* memory reclaimed. */
@Primitive(name = "gc_force")
public abstract static class GCForce extends PrimitiveArrayArgumentsNode {
@TruffleBoundary
@Specialization
Object force() {
// NOTE(norswap, 16 Apr 20): We could have used a WeakReference here, but the hope is that the extra
// indirection will prevent the compiler to optimize this method away (assuming JIT compilation, and
// the fact that such an optimizaton is permitted and possible, both of which are unlikely).
WeakValueCache