<commit_before>/*
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package com.oracle.graal.hotspot;

import java.lang.reflect.*;

import com.oracle.graal.hotspot.bridge.*;
import com.sun.management.HotSpotDiagnosticMXBean;

import sun.management.ManagementFactoryHelper;

/**
 * Used to access native configuration details.
 * 
 * All non-static, public fields in this class are final so that they can be compiled as constants.
 */
public final class HotSpotVMConfig extends CompilerObject {

    private static final long serialVersionUID = -4744897993263044184L;

    private final HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

    HotSpotVMConfig(CompilerToVM c2vm) {
        c2vm.initializeConfiguration(this);
        assert check();
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @return value of option
     * @throws IllegalArgumentException if option doesn't exist
     */
    private int getVMOptionInt(String name) {
        String value = diagnostic.getVMOption(name).getValue();
        return new Integer(value).intValue();
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @param defaultValue default value if option is not exists (e.g. development options)
     * @return value of option or defaultValue if option doesn't exist
     */
    private int getVMOption(String name, int defaultValue) {
        try {
            return getVMOptionInt(name);
        } catch (IllegalArgumentException e) {
            return defaultValue;
        }
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @return value of option
     * @throws IllegalArgumentException if option doesn't exist
     */
    private boolean getVMOption(String name) {
        String value = diagnostic.getVMOption(name).getValue();
        return new Boolean(value).booleanValue();
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @param defaultValue default value if option is not exists (e.g. development options)
     * @return value of option or defaultValue if option doesn't exist
     */
    private boolean getVMOption(String name, boolean defaultValue) {
        try {
            return getVMOption(name);
        } catch (IllegalArgumentException e) {
            return defaultValue;
        }
    }

    // Using systenm properties ensures the Java source compilers can never
    // optimize away an access to a config field<commit_msg>made methods for accessing HotSpot VM options static so they can be used without a HotSpotVMConfig object<commit_after>/*
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package com.oracle.graal.hotspot;

import java.lang.reflect.*;

import com.oracle.graal.hotspot.bridge.*;
import com.sun.management.HotSpotDiagnosticMXBean;

import sun.management.ManagementFactoryHelper;

/**
 * Used to access native configuration details.
 * 
 * All non-static, public fields in this class are final so that they can be compiled as constants.
 */
public final class HotSpotVMConfig extends CompilerObject {

    private static final long serialVersionUID = -4744897993263044184L;

    private static final HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

    HotSpotVMConfig(CompilerToVM c2vm) {
        c2vm.initializeConfiguration(this);
        assert check();
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @return value of option
     * @throws IllegalArgumentException if option doesn't exist
     */
    public static int getVMOptionInt(String name) {
        String value = diagnostic.getVMOption(name).getValue();
        return Integer.valueOf(value).intValue();
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @param defaultValue default value if option is not exists (e.g. development options)
     * @return value of option or defaultValue if option doesn't exist
     */
    public static int getVMOption(String name, int defaultValue) {
        try {
            return getVMOptionInt(name);
        } catch (IllegalArgumentException e) {
            return defaultValue;
        }
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @return value of option
     * @throws IllegalArgumentException if option doesn't exist
     */
    public static boolean getVMOption(String name) {
        String value = diagnostic.getVMOption(name).getValue();
        return Boolean.valueOf(value).booleanValue();
    }

    /**
     * Gets the value of an VM option.
     * 
     * @param name option's name
     * @param defaultValue default value if option is not exists (e.g. development options)
     * @return value of option or defaultValue if option doesn't exist
     */
    public static boolean getVMOption(String name, boolean defaultValue) {
        try {
            return getVMOption(name);
        } catch (IllegalArgumentException e) {
            return defaultValue;
        }
    }

    // Using systenm properties ensures the Java source compilers can never
    // optimize away an access to a config field
{'fraction_non_alphanumeric': 0.07087152825283896, 'fraction_numerical': 0.013955397455192229, 'mean_word_length': 2.9385775862068964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6746955', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1845, 'n_words': 806}