repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
tesseract-main/java/com/google/scrollview/events/SVEventHandler.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.events; import com.google.scrollview.ScrollView; import com.google.scrollview.events.SVEvent; import com.google.scrollview.events.SVEventType; import com.google.scrollview.ui.SVWindow; import org.piccolo2d.PCamera; import org.piccolo2d.PNode; import org.piccolo2d.event.PBasicInputEventHandler; import org.piccolo2d.event.PInputEvent; import org.piccolo2d.nodes.PPath; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.Window; import javax.swing.Timer; /** * The ScrollViewEventHandler takes care of any events which might happen on the * canvas and converts them to an according SVEvent, which is (using the * processEvent method) then added to a message queue. All events from the * message queue get sent gradually * * @author wanke@google.com */ public class SVEventHandler extends PBasicInputEventHandler implements ActionListener, KeyListener, WindowListener { /** Necessary to wait for a defined period of time (for SVET_HOVER). */ public Timer timer; /** The window which the event corresponds to. */ private SVWindow svWindow; /** These are used to determine a selection size (for SVET_SELECTION). */ private int lastX = 0; private int lastY = 0; /** * These are used in case we want to transmit our position, but do not get it * because it was no MouseEvent, in particular SVET_HOVER and SVET_INPUT. */ private int lastXMove = 0; private int lastYMove = 0; /** For Drawing a rubber-band rectangle for selection */ private int startX = 0; private int startY = 0; private float rubberBandTransparency = 0.5f; private PNode selection = null; /** The string entered since the last enter. Since the client * end eats all newlines, we can't use the newline * character, so use ! for now, as it cannot be entered * directly anyway and therefore can never show up for real. */ private String keyStr = "!"; /** Setup the timer. */ public SVEventHandler(SVWindow wdw) { timer = new Timer(1000, this); svWindow = wdw; } /** * Store the newest x,y values, add the message to the queue and restart the * timer. */ private void processEvent(SVEvent e) { lastXMove = e.x; lastYMove = e.y; ScrollView.addMessage(e); timer.restart(); } /** Show the associated popup menu at (x,y) (relative position of the window). */ private void showPopup(PInputEvent e) { double x = e.getCanvasPosition().getX(); double y = e.getCanvasPosition().getY(); if (svWindow.svPuMenu != null) { svWindow.svPuMenu.show(svWindow, (int) x, (int) y); } } /** The mouse is clicked - create an SVET_CLICK event. */ @Override public void mouseClicked(PInputEvent e) { if (e.isPopupTrigger()) { showPopup(e); } else { processEvent(new SVEvent(SVEventType.SVET_CLICK, svWindow, (int) e .getPosition().getX(), (int) e.getPosition().getY(), 0, 0, null)); } } /** * The mouse key is pressed (and keeps getting pressed). * Depending on the OS, show a popup menu (if the button pressed is associated * with popup menus, like the RMB under windows&linux) or otherwise save the * position (in case it is a selection). */ @Override public void mousePressed(PInputEvent e) { if (e.isPopupTrigger()) { showPopup(e); } else { lastX = (int) e.getPosition().getX(); lastY = (int) e.getPosition().getY(); timer.restart(); } } /** The mouse is getting dragged - create an SVET_MOUSE event. */ @Override public void mouseDragged(PInputEvent e) { processEvent(new SVEvent(SVEventType.SVET_MOUSE, svWindow, (int) e .getPosition().getX(), (int) e.getPosition().getY(), (int) e .getPosition().getX() - lastX, (int) e.getPosition().getY() - lastY, null)); // Paint a selection rectangle. if (selection == null) { startX = (int) e.getPosition().getX(); startY = (int) e.getPosition().getY(); selection = PPath.createRectangle(startX, startY, 1, 1); selection.setTransparency(rubberBandTransparency); svWindow.canvas.getLayer().addChild(selection); } else { int right = Math.max(startX, (int) e.getPosition().getX()); int left = Math.min(startX, (int) e.getPosition().getX()); int bottom = Math.max(startY, (int) e.getPosition().getY()); int top = Math.min(startY, (int) e.getPosition().getY()); svWindow.canvas.getLayer().removeChild(selection); selection = PPath.createRectangle(left, top, right - left, bottom - top); selection.setPaint(Color.YELLOW); selection.setTransparency(rubberBandTransparency); svWindow.canvas.getLayer().addChild(selection); } } /** * The mouse was released. * Depending on the OS, show a popup menu (if the button pressed is associated * with popup menus, like the RMB under windows&linux) or otherwise create an * SVET_SELECTION event. */ @Override public void mouseReleased(PInputEvent e) { if (e.isPopupTrigger()) { showPopup(e); } else { processEvent(new SVEvent(SVEventType.SVET_SELECTION, svWindow, (int) e .getPosition().getX(), (int) e.getPosition().getY(), (int) e .getPosition().getX() - lastX, (int) e.getPosition().getY() - lastY, null)); } if (selection != null) { svWindow.canvas.getLayer().removeChild(selection); selection = null; } } /** * The mouse wheel is used to zoom in and out of the viewport and center on * the (x,y) position the mouse is currently on. */ @Override public void mouseWheelRotated(PInputEvent e) { PCamera lc = svWindow.canvas.getCamera(); double sf = SVWindow.SCALING_FACTOR; if (e.getWheelRotation() < 0) { sf = 1 / sf; } lc.scaleViewAboutPoint(lc.getScale() / sf, e.getPosition().getX(), e .getPosition().getY()); } /** * The mouse was moved - create an SVET_MOTION event. NOTE: This obviously * creates a lot of traffic and, depending on the type of application, could * quite possibly be disabled. */ @Override public void mouseMoved(PInputEvent e) { processEvent(new SVEvent(SVEventType.SVET_MOTION, svWindow, (int) e .getPosition().getX(), (int) e.getPosition().getY(), 0, 0, null)); } /** * The mouse entered the window. * Start the timer, which will then emit SVET_HOVER events every X ms. */ @Override public void mouseEntered(PInputEvent e) { timer.restart(); } /** * The mouse exited the window * Stop the timer, so no more SVET_HOVER events will emit. */ @Override public void mouseExited(PInputEvent e) { timer.stop(); } /** * The only associated object with this is the timer, so we use it to send a * SVET_HOVER event. */ public void actionPerformed(ActionEvent e) { processEvent(new SVEvent(SVEventType.SVET_HOVER, svWindow, lastXMove, lastYMove, 0, 0, null)); } /** * A key was pressed - create an SVET_INPUT event. * * NOTE: Might be useful to specify hotkeys. * * Implementation note: The keyListener provided by Piccolo seems to be * broken, so we use the AWT listener directly. * There are never any keyTyped events received either so we are * stuck with physical keys, which is very ugly. */ public void keyPressed(KeyEvent e) { char keyCh = e.getKeyChar(); if (keyCh == '\r' || keyCh == '\n' || keyCh == '\0' || keyCh == '?') { processEvent(new SVEvent(SVEventType.SVET_INPUT, svWindow, lastXMove, lastYMove, 0, 0, keyStr)); // Send newline characters as '!' as '!' can never be a keypressed // and the client eats all newline characters. keyStr = "!"; } else { processEvent(new SVEvent(SVEventType.SVET_INPUT, svWindow, lastXMove, lastYMove, 0, 0, String.valueOf(keyCh))); keyStr += keyCh; } } /** * A window is closed (by the 'x') - create an SVET_DESTROY event. If it was * the last open Window, also send an SVET_EXIT event (but do not exit unless * the client says so). */ public void windowClosing(WindowEvent e) { processEvent(new SVEvent(SVEventType.SVET_DESTROY, svWindow, lastXMove, lastYMove, 0, 0, null)); Window w = e.getWindow(); if (w != null) { w.dispose(); } SVWindow.nrWindows--; if (SVWindow.nrWindows == 0) { processEvent(new SVEvent(SVEventType.SVET_EXIT, svWindow, lastXMove, lastYMove, 0, 0, null)); } } /** These are all events we do not care about and throw away */ public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public void windowActivated(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } }
9,822
31.52649
83
java
null
tesseract-main/java/com/google/scrollview/events/SVEvent.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.events; import com.google.scrollview.ui.SVWindow; /** * The SVEvent is a structure which holds the actual values of a message to be * transmitted. It corresponds to the client structure defined in scrollview.h * * @author wanke@google.com */ public class SVEvent { SVEventType type; // What kind of event. SVWindow window; // Window event relates to. int x; // Coords of click or selection. int y; int xSize; // Size of selection. int ySize; int commandId; String parameter; // Any string that might have been passed as argument. /** * A "normal" SVEvent. * * @param t The type of the event as specified in SVEventType (e.g. * SVET_CLICK) * @param w The window the event corresponds to * @param x1 X position of the mouse at the time of the event * @param y1 Y position of the mouse at the time of the event * @param x2 X selection size at the time of the event * @param y2 Y selection size at the time of the event * @param p A parameter associated with the event (e.g. keyboard input) */ public SVEvent(SVEventType t, SVWindow w, int x1, int y1, int x2, int y2, String p) { type = t; window = w; x = x1; y = y1; xSize = x2; ySize = y2; commandId = 0; parameter = p; } /** * An event which issues a command (like clicking on a item in the menubar). * * @param eventtype The type of the event as specified in SVEventType * (usually SVET_MENU or SVET_POPUP) * @param svWindow The window the event corresponds to * @param commandid The associated id with the command (given by the client * on construction of the item) * @param value A parameter associated with the event (e.g. keyboard input) */ public SVEvent(SVEventType eventtype, SVWindow svWindow, int commandid, String value) { type = eventtype; window = svWindow; parameter = value; x = 0; y = 0; xSize = 0; ySize = 0; commandId = commandid; } /** * This is the string representation of the message, which is what will * actually be transferred over the network. */ @Override public String toString() { return (window.hash + "," + type.ordinal() + "," + x + "," + y + "," + xSize + "," + ySize + "," + commandId + "," + parameter); } }
2,941
32.431818
80
java
null
tesseract-main/java/com/google/scrollview/ui/SVPopupMenu.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; import com.google.scrollview.events.SVEventType; import com.google.scrollview.ui.SVMenuItem; import com.google.scrollview.ui.SVWindow; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import javax.swing.JMenu; import javax.swing.JPopupMenu; /** * The SVPopupMenu class provides the functionality to add a popup menu to * ScrollView. Each popup menu item gets associated with a (client-defined) * command-id, which SVPopupMenu will return upon clicking it. * * @author wanke@google.com * */ public class SVPopupMenu implements ActionListener { /** The root entry to add items to. */ private JPopupMenu root; /** Contains a map of item name to its actual entry. */ private HashMap<String, SVAbstractMenuItem> items; /** The window the menubar belongs to. */ private SVWindow svWindow; /** * Create a new SVPopupMenu and associate it with a ScrollView window. * * @param sv The window our popup menu belongs to. */ SVPopupMenu(SVWindow sv) { root = new JPopupMenu(); svWindow = sv; items = new HashMap<String, SVAbstractMenuItem>(); } /** * Add a new entry to the menubar. For these items, the server will poll the * client to ask what to do. * * @param parent The menu we add our new entry to (should have been defined * before). If the parent is "", we will add the entry to the root * (top-level) * @param name The caption of the new entry. * @param id The Id of the new entry. If it is -1, the entry will be treated * as a menu. */ public void add(String parent, String name, int id) { // A duplicate entry - we just throw it away, since its already in. if (items.get(name) != null) { return; } // A new submenu at the top-level if (parent.equals("")) { JMenu jli = new JMenu(name); SVAbstractMenuItem mli = new SVSubMenuItem(name, jli); items.put(name, mli); root.add(jli); } // A new sub-submenu else if (id == -1) { SVAbstractMenuItem jmi = items.get(parent); JMenu jli = new JMenu(name); SVAbstractMenuItem mli = new SVSubMenuItem(name, jli); items.put(name, mli); jmi.add(jli); } // A new child entry. Add to appropriate parent. else { SVAbstractMenuItem jmi = items.get(parent); if (jmi == null) { System.out.println("ERROR: Unknown parent " + parent); System.exit(1); } SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name); mli.mi.addActionListener(this); items.put(name, mli); jmi.add(mli); } } /** * Add a new entry to the menubar. In this case, we also know its value and * possibly even have a description. For these items, the server will not poll * the client to ask what to do, but just show an input dialog and send a * message with the new value. * * @param parent The menu we add our new entry to (should have been defined * before). If the parent is "", we will add the entry to the root * (top-level) * @param name The caption of the new entry. * @param id The Id of the new entry. If it is -1, the entry will be treated * as a menu. * @param value The value of the new entry. * @param desc The description of the new entry. */ public void add(String parent, String name, int id, String value, String desc) { SVAbstractMenuItem jmi = items.get(parent); SVMenuItem mli = new SVMenuItem(id, name, value, desc); mli.mi.addActionListener(this); items.put(name, mli); if (jmi == null) { // add to root root.add(mli.mi); } else { // add to parent jmi.add(mli); } } /** * A click on one of the items in our menubar has occurred. Forward it * to the item itself to let it decide what happens. */ public void actionPerformed(ActionEvent e) { // Get the corresponding menuitem SVAbstractMenuItem svm = items.get(e.getActionCommand()); svm.performAction(svWindow, SVEventType.SVET_POPUP); } /** * Gets called by the SVEventHandler of the window to actually show the * content of the popup menu. */ public void show(Component Invoker, int x, int y) { root.show(Invoker, x, y); } }
4,926
32.97931
82
java
null
tesseract-main/java/com/google/scrollview/ui/SVSubMenuItem.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; /** * A MenuListItem is any sort of menu entry. This can either be within a popup * menu or within a menubar. It can either be a submenu (only name and * command-id) or a name with an associated value and possibly description. They * can also have new entries added (if they are submenus). * * @author wanke@google.com */ import javax.swing.JMenu; /** Constructs a new submenu which can hold other entries. */ class SVSubMenuItem extends SVAbstractMenuItem { public SVSubMenuItem(String name, JMenu jli) { super(-1, name, jli); } /** Adds a child entry to the submenu. */ @Override public void add(SVAbstractMenuItem mli) { mi.add(mli.mi); } /** Adds a child menu to the submenu (or root node). */ @Override public void add(JMenu jli) { mi.add(jli); } }
1,424
34.625
80
java
null
tesseract-main/java/com/google/scrollview/ui/SVAbstractMenuItem.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; /** * A MenuListItem is any sort of menu entry. This can either be within a popup * menu or within a menubar. It can either be a submenu (only name and * command-id) or a name with an associated value and possibly description. They * can also have new entries added (if they are submenus). * * @author wanke@google.com */ import com.google.scrollview.events.SVEventType; import javax.swing.JMenu; import javax.swing.JMenuItem; abstract class SVAbstractMenuItem { JMenuItem mi; public String name; public int id; /** * Sets the basic attributes for name, id and the corresponding swing item */ SVAbstractMenuItem(int id, String name, JMenuItem jmi) { this.mi = jmi; this.name = name; this.id = id; } /** Returns the actual value of the MenuListItem. */ public String getValue() { return null; } /** Adds a child entry to the submenu. */ public void add(SVAbstractMenuItem mli) { } /** Adds a child menu to the submenu (or root node). */ public void add(JMenu jli) { } /** * What to do when user clicks on this item. * @param window The window the event happened. * @param eventType What kind of event will be associated * (usually SVET_POPUP or SVET_MENU). */ public void performAction(SVWindow window, SVEventType eventType) {} }
1,935
32.37931
80
java
null
tesseract-main/java/com/google/scrollview/ui/SVCheckboxMenuItem.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; /** * A MenuListItem is any sort of menu entry. This can either be within a popup * menu or within a menubar. It can either be a submenu (only name and * command-id) or a name with an associated value and possibly description. They * can also have new entries added (if they are submenus). * * @author wanke@google.com */ import com.google.scrollview.ScrollView; import com.google.scrollview.events.SVEvent; import com.google.scrollview.events.SVEventType; import javax.swing.JCheckBoxMenuItem; /** * Constructs a new menulistitem which possesses a flag that can be toggled. */ class SVCheckboxMenuItem extends SVAbstractMenuItem { public boolean bvalue; SVCheckboxMenuItem(int id, String name, boolean val) { super(id, name, new JCheckBoxMenuItem(name, val)); bvalue = val; } /** What to do when user clicks on this item. */ @Override public void performAction(SVWindow window, SVEventType eventType) { // Checkbox entry - trigger and send event. if (bvalue) { bvalue = false; } else { bvalue = true; } SVEvent svme = new SVEvent(eventType, window, id, getValue()); ScrollView.addMessage(svme); } /** Returns the actual value of the MenuListItem. */ @Override public String getValue() { return Boolean.toString(bvalue); } }
1,939
32.448276
80
java
null
tesseract-main/java/com/google/scrollview/ui/SVMenuItem.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; /** * A MenuListItem is any sort of menu entry. This can either be within a popup * menu or within a menubar. It can either be a submenu (only name and * command-id) or a name with an associated value and possibly description. They * can also have new entries added (if they are submenus). * * @author wanke@google.com */ import com.google.scrollview.events.SVEventType; import javax.swing.JMenuItem; /** * Constructs a new menulistitem which also has a value and a description. For * these, we will not have to ask the server what the value is when the user * wants to change it, but can just call the client with the new value. */ class SVMenuItem extends SVAbstractMenuItem { public String value = null; public String desc = null; SVMenuItem(int id, String name, String v, String d) { super(id, name, new JMenuItem(name)); value = v; desc = d; } /** * Ask the user for new input for a variable and send it. * Depending on whether there is a description given for the entry, show * the description in the dialog or just show the name. */ @Override public void performAction(SVWindow window, SVEventType eventType) { if (desc != null) { window.showInputDialog(desc, value, id, eventType); } else { window.showInputDialog(name, value, id, eventType); } } /** Returns the actual value of the MenuListItem. */ @Override public String getValue() { return value; } }
2,085
33.196721
80
java
null
tesseract-main/java/com/google/scrollview/ui/SVWindow.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; import com.google.scrollview.ScrollView; import com.google.scrollview.events.SVEvent; import com.google.scrollview.events.SVEventHandler; import com.google.scrollview.events.SVEventType; import com.google.scrollview.ui.SVMenuBar; import com.google.scrollview.ui.SVPopupMenu; import org.piccolo2d.PCamera; import org.piccolo2d.PCanvas; import org.piccolo2d.PLayer; import org.piccolo2d.extras.swing.PScrollPane; import org.piccolo2d.nodes.PImage; import org.piccolo2d.nodes.PPath; import org.piccolo2d.nodes.PText; import org.piccolo2d.util.PPaintContext; import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.TextArea; import java.awt.geom.IllegalPathStateException; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; /** * The SVWindow is the top-level ui class. It should get instantiated whenever * the user intends to create a new window. It contains helper functions to draw * on the canvas, add new menu items, show modal dialogs etc. * * @author wanke@google.com */ public class SVWindow extends JFrame { /** * Constants defining the maximum initial size of the window. */ private static final int MAX_WINDOW_X = 1000; private static final int MAX_WINDOW_Y = 800; /* Constant defining the (approx) height of the default message box*/ private static final int DEF_MESSAGEBOX_HEIGHT = 200; /** Constant defining the "speed" at which to zoom in and out. */ public static final double SCALING_FACTOR = 2; /** The top level layer we add our PNodes to (root node). */ PLayer layer; /** The current color of the pen. It is used to draw edges, text, etc. */ Color currentPenColor; /** * The current color of the brush. It is used to draw the interior of * primitives. */ Color currentBrushColor; /** The system name of the current font we are using (e.g. * "Times New Roman"). */ Font currentFont; /** The stroke width to be used. */ // This really needs to be a fixed width stroke as the basic stroke is // anti-aliased and gets too faint, but the piccolo fixed width stroke // is too buggy and generates missing initial moveto in path definition // errors with a IllegalPathStateException that cannot be caught because // it is in the automatic repaint function. If we can fix the exceptions // in piccolo, then we can use the following instead of BasicStroke: // import edu.umd.cs.piccolox.util.PFixedWidthStroke; // PFixedWidthStroke stroke = new PFixedWidthStroke(0.5f); // Instead we use the BasicStroke and turn off anti-aliasing. BasicStroke stroke = new BasicStroke(0.5f); /** * A unique representation for the window, also known by the client. It is * used when sending messages from server to client to identify him. */ public int hash; /** * The total number of created Windows. If this ever reaches 0 (apart from the * beginning), quit the server. */ public static int nrWindows = 0; /** * The Canvas, MessageBox, EventHandler, Menubar and Popupmenu associated with * this window. */ private SVEventHandler svEventHandler = null; private SVMenuBar svMenuBar = null; private TextArea ta = null; public SVPopupMenu svPuMenu = null; public PCanvas canvas; private int winSizeX; private int winSizeY; /** Set the brush to an RGB color */ public void brush(int red, int green, int blue) { brush(red, green, blue, 255); } /** Set the brush to an RGBA color */ public void brush(int red, int green, int blue, int alpha) { // If alpha is zero, use a null brush to save rendering time. if (alpha == 0) { currentBrushColor = null; } else { currentBrushColor = new Color(red, green, blue, alpha); } } /** Erase all content from the window, but do not destroy it. */ public void clear() { // Manipulation of Piccolo's scene graph should be done from Swings // event dispatch thread since Piccolo is not thread safe. This code calls // removeAllChildren() from that thread and releases the latch. final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(1); SwingUtilities.invokeLater(new Runnable() { public void run() { layer.removeAllChildren(); repaint(); latch.countDown(); } }); try { latch.await(); } catch (InterruptedException e) { } } /** * Start setting up a new polyline. The server will now expect * polyline data until the polyline is complete. * * @param length number of coordinate pairs */ public void createPolyline(int length) { ScrollView.polylineXCoords = new float[length]; ScrollView.polylineYCoords = new float[length]; ScrollView.polylineSize = length; ScrollView.polylineScanned = 0; } /** * Draw the now complete polyline. */ public void drawPolyline() { int numCoords = ScrollView.polylineXCoords.length; if (numCoords < 2) { return; } PPath pn = PPath.createLine(ScrollView.polylineXCoords[0], ScrollView.polylineYCoords[0], ScrollView.polylineXCoords[1], ScrollView.polylineYCoords[1]); pn.reset(); pn.moveTo(ScrollView.polylineXCoords[0], ScrollView.polylineYCoords[0]); for (int p = 1; p < numCoords; ++p) { pn.lineTo(ScrollView.polylineXCoords[p], ScrollView.polylineYCoords[p]); } pn.closePath(); ScrollView.polylineSize = 0; pn.setStrokePaint(currentPenColor); pn.setPaint(null); // Don't fill the polygon - this is just a polyline. pn.setStroke(stroke); layer.addChild(pn); } /** * Construct a new SVWindow and set it visible. * * @param name Title of the window. * @param hash Unique internal representation. This has to be the same as * defined by the client, as they use this to refer to the windows. * @param posX X position of where to draw the window (upper left). * @param posY Y position of where to draw the window (upper left). * @param sizeX The width of the window. * @param sizeY The height of the window. * @param canvasSizeX The canvas width of the window. * @param canvasSizeY The canvas height of the window. */ public SVWindow(String name, int hash, int posX, int posY, int sizeX, int sizeY, int canvasSizeX, int canvasSizeY) { super(name); // Provide defaults for sizes. if (sizeX <= 0) sizeX = canvasSizeX; if (sizeY <= 0) sizeY = canvasSizeY; if (canvasSizeX <= 0) canvasSizeX = sizeX; if (canvasSizeY <= 0) canvasSizeY = sizeY; // Avoid later division by zero. if (sizeX <= 0) { sizeX = 1; canvasSizeX = sizeX; } if (sizeY <= 0) { sizeY = 1; canvasSizeY = sizeY; } // Initialize variables nrWindows++; this.hash = hash; this.svEventHandler = new SVEventHandler(this); this.currentPenColor = Color.BLACK; this.currentBrushColor = Color.BLACK; this.currentFont = new Font("Times New Roman", Font.PLAIN, 12); // Determine the initial size and zoom factor of the window. // If the window is too big, rescale it and zoom out. int shrinkfactor = 1; if (sizeX > MAX_WINDOW_X) { shrinkfactor = (sizeX + MAX_WINDOW_X - 1) / MAX_WINDOW_X; } if (sizeY / shrinkfactor > MAX_WINDOW_Y) { shrinkfactor = (sizeY + MAX_WINDOW_Y - 1) / MAX_WINDOW_Y; } winSizeX = sizeX / shrinkfactor; winSizeY = sizeY / shrinkfactor; double initialScalingfactor = 1.0 / shrinkfactor; if (winSizeX > canvasSizeX || winSizeY > canvasSizeY) { initialScalingfactor = Math.min(1.0 * winSizeX / canvasSizeX, 1.0 * winSizeY / canvasSizeY); } // Setup the actual window (its size, camera, title, etc.) if (canvas == null) { canvas = new PCanvas(); getContentPane().add(canvas, BorderLayout.CENTER); } layer = canvas.getLayer(); canvas.setBackground(Color.BLACK); // Disable antialiasing to make the lines more visible. canvas.setDefaultRenderQuality(PPaintContext.LOW_QUALITY_RENDERING); setLayout(new BorderLayout()); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); validate(); canvas.requestFocus(); // Manipulation of Piccolo's scene graph should be done from Swings // event dispatch thread since Piccolo is not thread safe. This code calls // initialize() from that thread once the PFrame is initialized, so you are // safe to start working with Piccolo in the initialize() method. SwingUtilities.invokeLater(new Runnable() { public void run() { repaint(); } }); setSize(winSizeX, winSizeY); setLocation(posX, posY); setTitle(name); // Add a Scrollpane to be able to scroll within the canvas PScrollPane scrollPane = new PScrollPane(canvas); getContentPane().add(scrollPane); scrollPane.setWheelScrollingEnabled(false); PCamera lc = canvas.getCamera(); lc.scaleViewAboutPoint(initialScalingfactor, 0, 0); // Disable the default event handlers and add our own. addWindowListener(svEventHandler); canvas.removeInputEventListener(canvas.getPanEventHandler()); canvas.removeInputEventListener(canvas.getZoomEventHandler()); canvas.addInputEventListener(svEventHandler); canvas.addKeyListener(svEventHandler); // Make the window visible. validate(); setVisible(true); } /** * Convenience function to add a message box to the window which can be used * to output debug information. */ public void addMessageBox() { if (ta == null) { ta = new TextArea(); ta.setEditable(false); getContentPane().add(ta, BorderLayout.SOUTH); } // We need to make the window bigger to accommodate the message box. winSizeY += DEF_MESSAGEBOX_HEIGHT; setSize(winSizeX, winSizeY); } /** * Allows you to specify the thickness with which to draw lines, recantgles * and ellipses. * @param width The new thickness. */ public void setStrokeWidth(float width) { // If this worked we wouldn't need the antialiased rendering off. // stroke = new PFixedWidthStroke(width); stroke = new BasicStroke(width); } /** * Draw an ellipse at (x,y) with given width and height, using the * current stroke, the current brush color to fill it and the * current pen color for the outline. */ public void drawEllipse(int x, int y, int width, int height) { PPath pn = PPath.createEllipse(x, y, width, height); pn.setStrokePaint(currentPenColor); pn.setStroke(stroke); pn.setPaint(currentBrushColor); layer.addChild(pn); } /** * Draw the image with the given name at (x,y). Any image loaded stays in * memory, so if you intend to redraw an image, you do not have to use * createImage again. */ public void drawImage(PImage img, int xPos, int yPos) { img.setX(xPos); img.setY(yPos); layer.addChild(img); } /** * Draw a line from (x1,y1) to (x2,y2) using the current pen color and stroke. */ public void drawLine(int x1, int y1, int x2, int y2) { PPath pn = PPath.createLine(x1, y1, x2, y2); pn.setStrokePaint(currentPenColor); pn.setPaint(null); // Null paint may render faster than the default. pn.setStroke(stroke); pn.moveTo(x1, y1); pn.lineTo(x2, y2); layer.addChild(pn); } /** * Draw a rectangle given the two points (x1,y1) and (x2,y2) using the current * stroke, pen color for the border and the brush to fill the * interior. */ public void drawRectangle(int x1, int y1, int x2, int y2) { if (x1 > x2) { int t = x1; x1 = x2; x2 = t; } if (y1 > y2) { int t = y1; y1 = y2; y2 = t; } PPath pn = PPath.createRectangle(x1, y1, x2 - x1, y2 - y1); pn.setStrokePaint(currentPenColor); pn.setStroke(stroke); pn.setPaint(currentBrushColor); layer.addChild(pn); } /** * Draw some text at (x,y) using the current pen color and text attributes. If * the current font does NOT support at least one character, it tries to find * a font which is capable of displaying it and use that to render the text. * Note: If the font says it can render a glyph, but in reality it turns out * to be crap, there is nothing we can do about it. */ public void drawText(int x, int y, String text) { int unreadableCharAt = -1; char[] chars = text.toCharArray(); PText pt = new PText(text); pt.setTextPaint(currentPenColor); pt.setFont(currentFont); // Check to see if every character can be displayed by the current font. for (int i = 0; i < chars.length; i++) { if (!currentFont.canDisplay(chars[i])) { // Set to the first not displayable character. unreadableCharAt = i; break; } } // Have to find some working font and use it for this text entry. if (unreadableCharAt != -1) { Font[] allfonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (int j = 0; j < allfonts.length; j++) { if (allfonts[j].canDisplay(chars[unreadableCharAt])) { Font tempFont = new Font(allfonts[j].getFontName(), currentFont.getStyle(), currentFont.getSize()); pt.setFont(tempFont); break; } } } pt.setX(x); pt.setY(y); layer.addChild(pt); } /** Set the pen color to an RGB value */ public void pen(int red, int green, int blue) { pen(red, green, blue, 255); } /** Set the pen color to an RGBA value */ public void pen(int red, int green, int blue, int alpha) { currentPenColor = new Color(red, green, blue, alpha); } /** * Define how to display text. Note: underlined is not currently not supported */ public void textAttributes(String font, int pixelSize, boolean bold, boolean italic, boolean underlined) { // For legacy reasons convert "Times" to "Times New Roman" if (font.equals("Times")) { font = "Times New Roman"; } int style = Font.PLAIN; if (bold) { style += Font.BOLD; } if (italic) { style += Font.ITALIC; } currentFont = new Font(font, style, pixelSize); } /** * Zoom the window to the rectangle given the two points (x1,y1) * and (x2,y2), which must be greater than (x1,y1). */ public void zoomRectangle(int x1, int y1, int x2, int y2) { if (x2 > x1 && y2 > y1) { winSizeX = getWidth(); winSizeY = getHeight(); int width = x2 - x1; int height = y2 - y1; // Since piccolo doesn't do this well either, pad with a margin // all the way around. int wmargin = width / 2; int hmargin = height / 2; double scalefactor = Math.min(winSizeX / (2.0 * wmargin + width), winSizeY / (2.0 * hmargin + height)); PCamera lc = canvas.getCamera(); lc.scaleView(scalefactor / lc.getViewScale()); lc.animateViewToPanToBounds(new Rectangle(x1 - hmargin, y1 - hmargin, 2 * wmargin + width, 2 * hmargin + height), 0); } } /** * Flush buffers and update display. * * Only actually reacts if there are no more messages in the stack, to prevent * the canvas from flickering. */ public void update() { // TODO(rays) fix bugs in piccolo or use something else. // The repaint function generates many // exceptions for no good reason. We catch and ignore as many as we // can here, but most of them are generated by the system repaints // caused by resizing/exposing parts of the window etc, and they // generate unwanted stack traces that have to be piped to /dev/null // (on linux). try { repaint(); } catch (NullPointerException e) { // Do nothing so the output isn't full of stack traces. } catch (IllegalPathStateException e) { // Do nothing so the output isn't full of stack traces. } } /** Adds a checkbox entry to the menubar, c.f. SVMenubar.add(...) */ public void addMenuBarItem(String parent, String name, int id, boolean checked) { svMenuBar.add(parent, name, id, checked); } /** Adds a submenu to the menubar, c.f. SVMenubar.add(...) */ public void addMenuBarItem(String parent, String name) { addMenuBarItem(parent, name, -1); } /** Adds a new entry to the menubar, c.f. SVMenubar.add(...) */ public void addMenuBarItem(String parent, String name, int id) { if (svMenuBar == null) { svMenuBar = new SVMenuBar(this); } svMenuBar.add(parent, name, id); } /** Add a message to the message box. */ public void addMessage(String message) { if (ta != null) { ta.append(message + "\n"); } else { System.out.println(message + "\n"); } } /** * This method converts a string which might contain hexadecimal values to a * string which contains the respective unicode counterparts. * * For example, Hall0x0094chen returns Hall<o umlaut>chen * encoded as utf8. * * @param input The original string, containing 0x values * @return The converted string which has the replaced unicode symbols */ private static String convertIntegerStringToUnicodeString(String input) { StringBuffer sb = new StringBuffer(input); Pattern numbers = Pattern.compile("0x[0-9a-fA-F]{4}"); Matcher matcher = numbers.matcher(sb); while (matcher.find()) { // Find the next match which resembles a hexadecimal value and convert it // to // its char value char a = (char) (Integer.decode(matcher.group()).intValue()); // Replace the original with the new character sb.replace(matcher.start(), matcher.end(), String.valueOf(a)); // Start again, since our positions have switched matcher.reset(); } return sb.toString(); } /** * Show a modal input dialog. The answer by the dialog is then send to the * client, together with the associated menu id, as SVET_POPUP * * @param msg The text that is displayed in the dialog. * @param def The default value of the dialog. * @param id The associated commandId * @param evtype The event this is associated with (usually SVET_MENU * or SVET_POPUP) */ public void showInputDialog(String msg, String def, int id, SVEventType evtype) { svEventHandler.timer.stop(); String tmp = (String) JOptionPane.showInputDialog(this, msg, "", JOptionPane.QUESTION_MESSAGE, null, null, def); if (tmp != null) { tmp = convertIntegerStringToUnicodeString(tmp); SVEvent res = new SVEvent(evtype, this, id, tmp); ScrollView.addMessage(res); } svEventHandler.timer.restart(); } /** * Shows a modal input dialog to the user. The return value is automatically * sent to the client as SVET_INPUT event (with command id -1). * * @param msg The text of the dialog. */ public void showInputDialog(String msg) { showInputDialog(msg, null, -1, SVEventType.SVET_INPUT); } /** * Shows a dialog presenting "Yes" and "No" as answers and returns either a * "y" or "n" to the client. * * Closing the dialog without answering is handled like "No". * * @param msg The text that is displayed in the dialog. */ public void showYesNoDialog(String msg) { // res returns 0 on yes, 1 on no. Seems to be a bit counterintuitive int res = JOptionPane.showOptionDialog(this, msg, "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); SVEvent e = new SVEvent(SVEventType.SVET_INPUT, this, 0, 0, 0, 0, res == 0 ? "y" : "n"); ScrollView.addMessage(e); } /** Adds a submenu to the popup menu, c.f. SVPopupMenu.add(...) */ public void addPopupMenuItem(String parent, String name) { if (svPuMenu == null) { svPuMenu = new SVPopupMenu(this); } svPuMenu.add(parent, name, -1); } /** Adds a new menu entry to the popup menu, c.f. SVPopupMenu.add(...) */ public void addPopupMenuItem(String parent, String name, int cmdEvent, String value, String desc) { if (svPuMenu == null) { svPuMenu = new SVPopupMenu(this); } svPuMenu.add(parent, name, cmdEvent, value, desc); } /** Destroys a window. */ public void destroy() { ScrollView.addMessage(new SVEvent(SVEventType.SVET_DESTROY, this, 0, "SVET_DESTROY")); setVisible(false); // dispose(); } }
21,612
32.302003
97
java
null
tesseract-main/java/com/google/scrollview/ui/SVImageHandler.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; import org.piccolo2d.nodes.PImage; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import javax.imageio.ImageIO; import javax.xml.bind.DatatypeConverter; /** * The ScrollViewImageHandler is a helper class which takes care of image * processing. It is used to construct an Image from the message-stream and * basically consists of a number of utility functions to process the input * stream. * * @author wanke@google.com */ public class SVImageHandler { /* All methods are static, so we forbid to construct SVImageHandler objects */ private SVImageHandler() { } /** * Reads size bytes from the stream in and interprets it as an image file, * encoded as png, and then text-encoded as base 64, returning the decoded * bitmap. * * @param size The size of the image file. * @param in The input stream from which to read the bytes. */ public static PImage readImage(int size, BufferedReader in) { char[] charbuffer = new char[size]; int numRead = 0; while (numRead < size) { int newRead = -1; try { newRead = in.read(charbuffer, numRead, size - numRead); } catch (IOException e) { System.out.println("Failed to read image data from socket:" + e.getMessage()); return null; } if (newRead < 0) { return null; } numRead += newRead; } if (numRead != size) { System.out.println("Failed to read image data from socket"); return null; } // Convert the character data to binary. byte[] binarydata = DatatypeConverter.parseBase64Binary(new String(charbuffer)); // Convert the binary data to a byte stream and parse to image. ByteArrayInputStream byteStream = new ByteArrayInputStream(binarydata); try { PImage img = new PImage(ImageIO.read(byteStream)); return img; } catch (IOException e) { System.out.println("Failed to decode image data from socket" + e.getMessage()); } return null; } }
2,658
34.453333
86
java
null
tesseract-main/java/com/google/scrollview/ui/SVEmptyMenuItem.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; /** * A MenuListItem is any sort of menu entry. This can either be within a popup * menu or within a menubar. It can either be a submenu (only name and * command-id) or a name with an associated value and possibly description. They * can also have new entries added (if they are submenus). * * @author wanke@google.com */ import com.google.scrollview.ScrollView; import com.google.scrollview.events.SVEvent; import com.google.scrollview.events.SVEventType; import javax.swing.JMenuItem; /** * Constructs a new menulistitem which just has an ID and a name attached to * it. In this case, we will have to ask for the value of the item and its * description if it gets called. */ class SVEmptyMenuItem extends SVAbstractMenuItem { SVEmptyMenuItem(int id, String name) { super(id, name, new JMenuItem(name)); } /** What to do when user clicks on this item. */ @Override public void performAction(SVWindow window, SVEventType eventType) { // Send an event indicating that someone clicked on an entry. // Value will be null here. SVEvent svme = new SVEvent(eventType, window, id, getValue()); ScrollView.addMessage(svme); } }
1,799
37.297872
80
java
null
tesseract-main/java/com/google/scrollview/ui/SVMenuBar.java
// Copyright 2007 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); You may not // use this file except in compliance with the License. You may obtain a copy of // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by // applicable law or agreed to in writing, software distributed under the // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. package com.google.scrollview.ui; import com.google.scrollview.events.SVEventType; import com.google.scrollview.ui.SVWindow; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import javax.swing.JMenu; import javax.swing.JMenuBar; /** * The SVMenuBar class provides the functionality to add a menubar to * ScrollView. Each menubar item gets associated with a (client-defined) * command-id, which SVMenuBar will return upon clicking it. * * @author wanke@google.com * */ public class SVMenuBar implements ActionListener { /** The root entry to add items to. */ private JMenuBar root; /** Contains a map of item name to its actual entry. */ private HashMap<String, SVAbstractMenuItem> items; /** The window the menubar belongs to. */ private SVWindow svWindow; /** * Create a new SVMenuBar and place it at the top of the ScrollView window. * * @param scrollView The window our menubar belongs to. */ public SVMenuBar(SVWindow scrollView) { root = new JMenuBar(); svWindow = scrollView; items = new HashMap<String, SVAbstractMenuItem>(); svWindow.setJMenuBar(root); } /** * A click on one of the items in our menubar has occurred. Forward it * to the item itself to let it decide what happens. */ public void actionPerformed(ActionEvent e) { // Get the corresponding menuitem. SVAbstractMenuItem svm = items.get(e.getActionCommand()); svm.performAction(svWindow, SVEventType.SVET_MENU); } /** * Add a new entry to the menubar. * * @param parent The menu we add our new entry to (should have been defined * before). If the parent is "", we will add the entry to the root * (top-level) * @param name The caption of the new entry. * @param id The Id of the new entry. If it is -1, the entry will be treated * as a menu. */ public void add(String parent, String name, int id) { // A duplicate entry - we just throw it away, since its already in. if (items.get(name) != null) { return; } // A new submenu at the top-level if (parent.equals("")) { JMenu jli = new JMenu(name); SVAbstractMenuItem mli = new SVSubMenuItem(name, jli); items.put(name, mli); root.add(jli); } // A new sub-submenu else if (id == -1) { SVAbstractMenuItem jmi = items.get(parent); JMenu jli = new JMenu(name); SVAbstractMenuItem mli = new SVSubMenuItem(name, jli); items.put(name, mli); jmi.add(jli); } // A new child entry. Add to appropriate parent. else { SVAbstractMenuItem jmi = items.get(parent); if (jmi == null) { System.out.println("ERROR: Unknown parent " + parent); System.exit(1); } SVAbstractMenuItem mli = new SVEmptyMenuItem(id, name); mli.mi.addActionListener(this); items.put(name, mli); jmi.add(mli); } } /** * Add a new checkbox entry to the menubar. * * @param parent The menu we add our new entry to (should have been defined * before). If the parent is "", we will add the entry to the root * (top-level) * @param name The caption of the new entry. * @param id The Id of the new entry. If it is -1, the entry will be treated * as a menu. * @param b Whether the entry is initially flagged. * */ public void add(String parent, String name, int id, boolean b) { SVAbstractMenuItem jmi = items.get(parent); if (jmi == null) { System.out.println("ERROR: Unknown parent " + parent); System.exit(1); } SVAbstractMenuItem mli = new SVCheckboxMenuItem(id, name, b); mli.mi.addActionListener(this); items.put(name, mli); jmi.add(mli); } }
4,362
32.305344
80
java
JAVAEncryption
JAVAEncryption-master/src/com/main/AES/AES128CBCPKCS5.java
package com.main.AES; import java.security.MessageDigest; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * AES 128 bit CBC PKCS5 padding example * */ public class AES128CBCPKCS5 { public static void main(String[] args) throws Exception { String key = "EncodeStuff00000"; String input = "sample test to encrypt"; String encrypted = encrypt(input, key); System.out.println("encrypted data: " + encrypted); String decrypted = decrypt(encrypted, key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param plainText * @param key * @return * @throws Exception */ public static String encrypt(String plainText, String key) throws Exception { byte[] inputByte = plainText.getBytes(); // Generating IV. int ivSize = 16; byte[] iv = new byte[ivSize]; SecureRandom random = new SecureRandom(); random.nextBytes(iv); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Hashing key. MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(key.getBytes("UTF-8")); byte[] keyBytes = new byte[16]; System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); // Encrypt. Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] encrypted = cipher.doFinal(inputByte); // Combine IV and encrypted part. byte[] encryptedIVAndText = new byte[ivSize + encrypted.length]; System.arraycopy(iv, 0, encryptedIVAndText, 0, ivSize); System.arraycopy(encrypted, 0, encryptedIVAndText, ivSize, encrypted.length); return Base64.encodeBase64String(encryptedIVAndText); } /** * * @param encryptedIvText * @param key * @return * @throws Exception */ public static String decrypt(String encryptedIvText, String key) throws Exception { int ivSize = 16; int keySize = 16; byte[] encryptedIvTextBytes = Base64.decodeBase64(encryptedIvText); // Extract IV. byte[] iv = new byte[ivSize]; System.arraycopy(encryptedIvTextBytes, 0, iv, 0, iv.length); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Extract encrypted part. int encryptedSize = encryptedIvTextBytes.length - ivSize; byte[] encryptedBytes = new byte[encryptedSize]; System.arraycopy(encryptedIvTextBytes, ivSize, encryptedBytes, 0, encryptedSize); // Hash key. byte[] keyBytes = new byte[keySize]; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(key.getBytes()); System.arraycopy(md.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); // Decrypt. Cipher cipherDecrypt = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipherDecrypt.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] decrypted = cipherDecrypt.doFinal(encryptedBytes); return new String(decrypted); } }
3,141
27.825688
84
java
JAVAEncryption
JAVAEncryption-master/src/com/main/AES/AES128CBCwithNOPadding.java
package com.main.AES; import java.security.MessageDigest; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * AES 128 bit CBC No padding example * */ public class AES128CBCwithNOPadding { public static void main(String[] args) throws Exception { String key = "EncodeStuff00000"; String data = "16CharacterInput";// input should be multiple of 16 String encrypted = encrypt(data, key); System.out.println("encrypted data: " + encrypted); String decrypted = decrypt(encrypted, key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param plainText * @param key * @return * @throws Exception */ public static String encrypt(String plainText, String key) throws Exception { byte[] inputByte = plainText.getBytes(); // Generating IV. int ivSize = 16; byte[] iv = new byte[ivSize]; SecureRandom random = new SecureRandom(); random.nextBytes(iv); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Hashing key. MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(key.getBytes("UTF-8")); byte[] keyBytes = new byte[16]; System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); // Encrypt. Cipher cipher = Cipher.getInstance("AES/CBC/NOPadding"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] encrypted = cipher.doFinal(inputByte); // Combine IV and encrypted part. byte[] encryptedIVAndText = new byte[ivSize + encrypted.length]; System.arraycopy(iv, 0, encryptedIVAndText, 0, ivSize); System.arraycopy(encrypted, 0, encryptedIVAndText, ivSize, encrypted.length); return Base64.encodeBase64String(encryptedIVAndText); } /** * * @param encryptedIvText * @param key * @return * @throws Exception */ public static String decrypt(String encryptedIvText, String key) throws Exception { int ivSize = 16; int keySize = 16; byte[] encryptedIvTextBytes = Base64.decodeBase64(encryptedIvText); // Extract IV. byte[] iv = new byte[ivSize]; System.arraycopy(encryptedIvTextBytes, 0, iv, 0, iv.length); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Extract encrypted part. int encryptedSize = encryptedIvTextBytes.length - ivSize; byte[] encryptedBytes = new byte[encryptedSize]; System.arraycopy(encryptedIvTextBytes, ivSize, encryptedBytes, 0, encryptedSize); // Hash key. byte[] keyBytes = new byte[keySize]; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(key.getBytes()); System.arraycopy(md.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); // Decrypt. Cipher cipherDecrypt = Cipher.getInstance("AES/CBC/NOPadding"); cipherDecrypt.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] decrypted = cipherDecrypt.doFinal(encryptedBytes); return new String(decrypted); } }
3,168
27.54955
84
java
JAVAEncryption
JAVAEncryption-master/src/com/main/AES/AES128ECBwithNoPadding.java
package com.main.AES; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * AES 128 bit ECB No padding example * */ public class AES128ECBwithNoPadding { public static void main(String[] args) { String key = "EncodeStuff00000"; // encryption key should be 16 // character long String data = "16CharacterInput";// input should be multiple of 16 System.out.println("encrypted data: " + AES128ECBwithNoPadding.encrypt(data, key)); System.out.println( "decrypted data: " + AES128ECBwithNoPadding.decrypt(AES128ECBwithNoPadding.encrypt(data, key), key)); } /** * encrypt input text * * @param input * @param key * @return */ public static String encrypt(String input, String key) { byte[] crypted = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/NOPadding"); cipher.init(Cipher.ENCRYPT_MODE, skey); crypted = cipher.doFinal(input.getBytes()); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return new String(Base64.encodeBase64(crypted)); } /** * decrypt input text * * @param input * @param key * @return */ public static String decrypt(String input, String key) { byte[] output = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/NOPadding"); cipher.init(Cipher.DECRYPT_MODE, skey); output = cipher.doFinal(Base64.decodeBase64(input)); } catch (Exception e) { System.out.println(e.toString()); } return new String(output); } }
1,715
22.506849
105
java
JAVAEncryption
JAVAEncryption-master/src/com/main/AES/AES128ECBwithPKCS5.java
package com.main.AES; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * AES 128 bit ECB PKCS5 padding example * */ public class AES128ECBwithPKCS5 { public static void main(String[] args) { // encryption key should be 16 character long String key = "EncodeStuff00000"; String data = "some text to encrypt"; String encrypted = AES128ECBwithPKCS5.encrypt(data, key); System.out.println("encrypted data: " + encrypted); String decrypted = AES128ECBwithPKCS5.decrypt(AES128ECBwithPKCS5.encrypt(data, key), key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param input * @param key * @return */ public static String encrypt(String input, String key) { byte[] crypted = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skey); crypted = cipher.doFinal(input.getBytes()); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return new String(Base64.encodeBase64(crypted)); } /** * decrypt input text * @param input * @param key * @return */ public static String decrypt(String input, String key) { byte[] output = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skey); output = cipher.doFinal(Base64.decodeBase64(input)); } catch (Exception e) { System.out.println(e.toString()); } return new String(output); } }
1,721
22.589041
92
java
JAVAEncryption
JAVAEncryption-master/src/com/main/AES/AES128ECBwithPKCS7.java
package com.main.AES; import java.security.Security; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; import javax.crypto.Cipher; import javax.crypto.Mac; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import javax.crypto.Cipher; import javax.crypto.Mac; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import javax.crypto.Cipher; import javax.crypto.Mac; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec;/** * * @author Ajit * * AES 128 bit ECB PKCS7 padding example * */ public class AES128ECBwithPKCS7 { //add new bouncycastle ciphers static { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); } public static void main(String[] args) { // encryption key should be multiple of 16 character long String key = "EncodeStuff00000"; String data = "some text to encrypt"; String encrypted = AES128ECBwithPKCS7.encrypt(data, key); System.out.println("encrypted data: " + encrypted); String decrypted = AES128ECBwithPKCS7.decrypt(AES128ECBwithPKCS7.encrypt(data, key), key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param input * @param key * @return */ public static String encrypt(String input, String key) { byte[] crypted = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); cipher.init(Cipher.ENCRYPT_MODE, skey); crypted = cipher.doFinal(input.getBytes()); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return new String(Base64.encodeBase64(crypted)); } /** * decrypt input text * * @param input * @param key * @return */ public static String decrypt(String input, String key) { byte[] output = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); cipher.init(Cipher.DECRYPT_MODE, skey); output = cipher.doFinal(Base64.decodeBase64(input)); } catch (Exception e) { System.out.println(e.toString()); } return new String(output); } }
2,314
23.368421
92
java
JAVAEncryption
JAVAEncryption-master/src/com/main/DES/DES128CBCPKCS5.java
package com.main.DES; import java.security.MessageDigest; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * AES 128 bit CBC PKCS5 padding example * */ public class DES128CBCPKCS5 { public static void main(String[] args) throws Exception { // encryption key should be 8 character or multiple of 8 character long String key = "12345678"; String input = "sample test to encrypt"; String encrypted = encrypt(input, key); System.out.println("encrypted data: " + encrypted); String decrypted = decrypt(encrypted, key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param plainText * @param key * @return * @throws Exception */ public static String encrypt(String plainText, String key) throws Exception { byte[] inputByte = plainText.getBytes(); // Generating IV. int ivSize = 8; byte[] iv = new byte[ivSize]; SecureRandom random = new SecureRandom(); random.nextBytes(iv); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Hashing key. MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(key.getBytes("UTF-8")); byte[] keyBytes = new byte[8]; System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); // Encrypt. Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] encrypted = cipher.doFinal(inputByte); // Combine IV and encrypted part. byte[] encryptedIVAndText = new byte[ivSize + encrypted.length]; System.arraycopy(iv, 0, encryptedIVAndText, 0, ivSize); System.arraycopy(encrypted, 0, encryptedIVAndText, ivSize, encrypted.length); return Base64.encodeBase64String(encryptedIVAndText); } /** * * @param encryptedIvText * @param key * @return * @throws Exception */ public static String decrypt(String encryptedIvText, String key) throws Exception { int ivSize = 8; int keySize = 8; byte[] encryptedIvTextBytes = Base64.decodeBase64(encryptedIvText); // Extract IV. byte[] iv = new byte[ivSize]; System.arraycopy(encryptedIvTextBytes, 0, iv, 0, iv.length); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Extract encrypted part. int encryptedSize = encryptedIvTextBytes.length - ivSize; byte[] encryptedBytes = new byte[encryptedSize]; System.arraycopy(encryptedIvTextBytes, ivSize, encryptedBytes, 0, encryptedSize); // Hash key. byte[] keyBytes = new byte[keySize]; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(key.getBytes()); System.arraycopy(md.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); // Decrypt. Cipher cipherDecrypt = Cipher.getInstance("DES/CBC/PKCS5Padding"); cipherDecrypt.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] decrypted = cipherDecrypt.doFinal(encryptedBytes); return new String(decrypted); } }
3,206
27.891892
84
java
JAVAEncryption
JAVAEncryption-master/src/com/main/DES/DES128CBCPKCSNoPadding.java
package com.main.DES; import java.security.MessageDigest; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * DES 128 bit CBC no padding example * */ public class DES128CBCPKCSNoPadding { public static void main(String[] args) throws Exception { // encryption key should be 8 character long String key = "12345678"; String data = "somedata";// input should be multiple of 8 String encrypted = encrypt(data, key); System.out.println("encrypted data: " + encrypted); String decrypted = decrypt(encrypted, key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param plainText * @param key * @return * @throws Exception */ public static String encrypt(String plainText, String key) throws Exception { byte[] inputByte = plainText.getBytes(); // Generating IV. int ivSize = 8; byte[] iv = new byte[ivSize]; SecureRandom random = new SecureRandom(); random.nextBytes(iv); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Hashing key. MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(key.getBytes("UTF-8")); byte[] keyBytes = new byte[8]; System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); // Encrypt. Cipher cipher = Cipher.getInstance("DES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] encrypted = cipher.doFinal(inputByte); // Combine IV and encrypted part. byte[] encryptedIVAndText = new byte[ivSize + encrypted.length]; System.arraycopy(iv, 0, encryptedIVAndText, 0, ivSize); System.arraycopy(encrypted, 0, encryptedIVAndText, ivSize, encrypted.length); return Base64.encodeBase64String(encryptedIVAndText); } /** * * @param encryptedIvText * @param key * @return * @throws Exception */ public static String decrypt(String encryptedIvText, String key) throws Exception { int ivSize = 8; int keySize = 8; byte[] encryptedIvTextBytes = Base64.decodeBase64(encryptedIvText); // Extract IV. byte[] iv = new byte[ivSize]; System.arraycopy(encryptedIvTextBytes, 0, iv, 0, iv.length); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); // Extract encrypted part. int encryptedSize = encryptedIvTextBytes.length - ivSize; byte[] encryptedBytes = new byte[encryptedSize]; System.arraycopy(encryptedIvTextBytes, ivSize, encryptedBytes, 0, encryptedSize); // Hash key. byte[] keyBytes = new byte[keySize]; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(key.getBytes()); System.arraycopy(md.digest(), 0, keyBytes, 0, keyBytes.length); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); // Decrypt. Cipher cipherDecrypt = Cipher.getInstance("DES/CBC/NoPadding"); cipherDecrypt.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] decrypted = cipherDecrypt.doFinal(encryptedBytes); return new String(decrypted); } }
3,197
27.553571
84
java
JAVAEncryption
JAVAEncryption-master/src/com/main/DES/DES128ECBwithNoPadding.java
package com.main.DES; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * DES 128 bit ECB No padding example * */ public class DES128ECBwithNoPadding { public static void main(String[] args) { // encryption key should be 8 character long String key = "12345678"; String data = "somedata";// input should be multiple of 8 String encrypted = DES128ECBwithNoPadding.encrypt(data, key); System.out.println("encrypted data: " + encrypted); String decrypted = DES128ECBwithNoPadding.decrypt(DES128ECBwithNoPadding.encrypt(data, key), key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param input * @param key * @return */ public static String encrypt(String input, String key) { byte[] crypted = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, skey); crypted = cipher.doFinal(input.getBytes()); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return new String(Base64.encodeBase64(crypted)); } /** * decrypt input text * * @param input * @param key * @return */ public static String decrypt(String input, String key) { byte[] output = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, skey); output = cipher.doFinal(Base64.decodeBase64(input)); } catch (Exception e) { System.out.println(e.toString()); } return new String(output); } }
1,753
22.386667
100
java
JAVAEncryption
JAVAEncryption-master/src/com/main/DES/DES128ECBwithPKCS5.java
package com.main.DES; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; /** * * @author Ajit * * DES 128 bit ECB PKCS5 padding example * */ public class DES128ECBwithPKCS5 { public static void main(String[] args) { // encryption key should be 8 character or multiple of 8 character long String key = "EncodeSf"; String data = "some text to encrypt"; String encrypted = DES128ECBwithPKCS5.encrypt(data, key); System.out.println("encrypted data: " + encrypted); String decrypted = DES128ECBwithPKCS5.decrypt(DES128ECBwithPKCS5.encrypt(data, key), key); System.out.println("decrypted data: " + decrypted); } /** * encrypt input text * * @param input * @param key * @return */ public static String encrypt(String input, String key) { byte[] crypted = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skey); crypted = cipher.doFinal(input.getBytes()); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return new String(Base64.encodeBase64(crypted)); } /** * decrypt input text * @param input * @param key * @return */ public static String decrypt(String input, String key) { byte[] output = null; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skey); output = cipher.doFinal(Base64.decodeBase64(input)); } catch (Exception e) { System.out.println(e.toString()); } return new String(output); } }
1,739
22.835616
92
java
jmh
jmh-master/jmh-ant-sample/src/org/openjdk/jmh/MyAntyBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh; import org.openjdk.jmh.annotations.Benchmark; import java.util.concurrent.TimeUnit; public class MyAntyBench { @Benchmark public void myTest() throws InterruptedException { TimeUnit.MILLISECONDS.sleep(1); } }
1,472
36.769231
79
java
jmh
jmh-master/jmh-archetypes/jmh-java-benchmark-archetype/src/main/resources/archetype-resources/src/main/java/MyBenchmark.java
/* * Copyright (c) 2014, Oracle America, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Oracle nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ package ${groupId}; import org.openjdk.jmh.annotations.Benchmark; public class MyBenchmark { @Benchmark public void testMethod() { // This is a demo/sample template for building your JMH benchmarks. Edit as needed. // Put your benchmark code here. } }
1,863
40.422222
91
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/BlackholeBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) public class BlackholeBench { private List<String> strs; @Setup(Level.Iteration) public void makeGarbage() { // make some garbage to evict blackhole from the TLAB/eden strs = new ArrayList<>(); for (int i = 0; i < 100_000; i++) { strs.add("str" + i); } } public byte b; public boolean bool; public char c; public short s; public int i; public long l; public float f; public double d; public Object o; public Object[] os; @Benchmark public void baseline() { // do nothing } @Benchmark public byte implicit_byte() { return b; } @Benchmark public boolean implicit_boolean() { return bool; } @Benchmark public char implicit_char() { return c; } @Benchmark public short implicit_short() { return s; } @Benchmark public int implicit_int() { return i; } @Benchmark public long implicit_long() { return l; } @Benchmark public float implicit_float() { return f; } @Benchmark public double implicit_double() { return d; } @Benchmark public Object implicit_Object() { return o; } @Benchmark public Object[] implicit_Array() { return os; } @Benchmark public void explicit_byte(Blackhole bh) { bh.consume(b); } @Benchmark public void explicit_boolean(Blackhole bh) { bh.consume(bool); } @Benchmark public void explicit_char(Blackhole bh) { bh.consume(c); } @Benchmark public void explicit_short(Blackhole bh) { bh.consume(s); } @Benchmark public void explicit_int(Blackhole bh) { bh.consume(i); } @Benchmark public void explicit_long(Blackhole bh) { bh.consume(l); } @Benchmark public void explicit_float(Blackhole bh) { bh.consume(f); } @Benchmark public void explicit_double(Blackhole bh) { bh.consume(d); } @Benchmark public void explicit_Object(Blackhole bh) { bh.consume(o); } @Benchmark public void explicit_Array(Blackhole bh) { bh.consume(os); } }
3,799
21.754491
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/BlackholeConsecutiveBench.java
/* * Copyright (c) 2014, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @State(Scope.Thread) public class BlackholeConsecutiveBench { private int x = 4242; private int y = 1414; @Benchmark public void test_boolean_1(Blackhole bh) { bh.consume((x / y + 1331) > 0); } @Benchmark public void test_boolean_4(Blackhole bh) { bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); } @Benchmark public void test_boolean_8(Blackhole bh) { bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); bh.consume((x / y + 1331) > 0); } @Benchmark public void test_byte_1(Blackhole bh) { bh.consume((byte) (x / y + 1331)); } @Benchmark public void test_byte_4(Blackhole bh) { bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); } @Benchmark public void test_byte_8(Blackhole bh) { bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); bh.consume((byte) (x / y + 1331)); } @Benchmark public void test_short_1(Blackhole bh) { bh.consume((short) (x / y + 1331)); } @Benchmark public void test_short_4(Blackhole bh) { bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); } @Benchmark public void test_short_8(Blackhole bh) { bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); bh.consume((short) (x / y + 1331)); } @Benchmark public void test_char_1(Blackhole bh) { bh.consume((char) (x / y + 1331)); } @Benchmark public void test_char_4(Blackhole bh) { bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); } @Benchmark public void test_char_8(Blackhole bh) { bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); bh.consume((char) (x / y + 1331)); } @Benchmark public void test_int_1(Blackhole bh) { bh.consume((int) (x / y + 1331)); } @Benchmark public void test_int_4(Blackhole bh) { bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); } @Benchmark public void test_int_8(Blackhole bh) { bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); bh.consume((int) (x / y + 1331)); } @Benchmark public void test_float_1(Blackhole bh) { bh.consume((float) (x / y + 1331)); } @Benchmark public void test_float_4(Blackhole bh) { bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); } @Benchmark public void test_float_8(Blackhole bh) { bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); bh.consume((float) (x / y + 1331)); } @Benchmark public void test_long_1(Blackhole bh) { bh.consume((long) (x / y + 1331)); } @Benchmark public void test_long_4(Blackhole bh) { bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); } @Benchmark public void test_long_8(Blackhole bh) { bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); bh.consume((long) (x / y + 1331)); } @Benchmark public void test_double_1(Blackhole bh) { bh.consume((double) (x / y + 1331)); } @Benchmark public void test_double_4(Blackhole bh) { bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); } @Benchmark public void test_double_8(Blackhole bh) { bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); bh.consume((double) (x / y + 1331)); } @Benchmark public void test_Object_1(Blackhole bh) { bh.consume(cachedObject(x / y + 1331)); } @Benchmark public void test_Object_4(Blackhole bh) { bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); } @Benchmark public void test_Object_8(Blackhole bh) { bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); bh.consume(cachedObject(x / y + 1331)); } private Object cachedObject(int v) { if (v == 4242/1414 + 1331) { return 42; } else { return v; } } }
8,625
29.480565
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/BlackholeConsumeCPUBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(3) @State(Scope.Benchmark) public class BlackholeConsumeCPUBench { @Param("0") private int delay; @Benchmark public void consume() { Blackhole.consumeCPU(delay); } }
1,772
35.9375
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/BlackholePipelineBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.Random; import java.util.concurrent.TimeUnit; @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class BlackholePipelineBench { @Param("10") private int steps; private boolean[] booleans; private byte[] bytes; private short[] shorts; private char[] chars; private int[] ints; private float[] floats; private long[] longs; private double[] doubles; private Object[] objects; private Object[][] arrays; @Setup public void prepare() { booleans = new boolean[steps]; bytes = new byte[steps]; shorts = new short[steps]; chars = new char[steps]; ints = new int[steps]; floats = new float[steps]; longs = new long[steps]; doubles = new double[steps]; objects = new Object[steps]; arrays = new Object[steps][]; Random r = new Random(0); for (int c = 0; c < steps; c++) { booleans[c] = r.nextBoolean(); bytes[c] = (byte) r.nextInt(); shorts[c] = (short) r.nextInt(); chars[c] = (char) r.nextInt(); ints[c] = r.nextInt(); floats[c] = r.nextFloat(); longs[c] = r.nextLong(); doubles[c] = r.nextDouble(); objects[c] = new Object(); arrays[c] = new Object[10]; } } @Benchmark public void test_boolean(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(booleans[c]); } } @Benchmark public void test_byte(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(bytes[c]); } } @Benchmark public void test_short(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(shorts[c]); } } @Benchmark public void test_char(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(chars[c]); } } @Benchmark public void test_int(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(ints[c]); } } @Benchmark public void test_float(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(floats[c]); } } @Benchmark public void test_long(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(longs[c]); } } @Benchmark public void test_double(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(doubles[c]); } } @Benchmark public void test_Object(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(objects[c]); } } @Benchmark public void test_Array(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(arrays[c]); } } }
4,256
27.192053
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/BlackholePipelinePayloadBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class BlackholePipelinePayloadBench { @Param("10") private int steps; private boolean[] booleans; private byte[] bytes; private short[] shorts; private char[] chars; private int[] ints; private float[] floats; private long[] longs; private double[] doubles; private Double[] objects; private Double[][] arrays; @Setup public void prepare() { booleans = new boolean[steps]; bytes = new byte[steps]; shorts = new short[steps]; chars = new char[steps]; ints = new int[steps]; floats = new float[steps]; longs = new long[steps]; doubles = new double[steps]; objects = new Double[steps]; arrays = new Double[steps][]; for (int c = 0; c < steps; c++) { booleans[c] = ((c & 1) == 0); bytes[c] = (byte) c; shorts[c] = (short) c; chars[c] = (char) c; ints[c] = c; floats[c] = c; longs[c] = c; doubles[c] = c; objects[c] = (double) c; arrays[c] = new Double[]{(double) c}; } } @Benchmark public void test_boolean(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((Math.log(doubles[c]) > 1) ^ booleans[c]); } } @Benchmark public void test_byte(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((byte)Math.log(bytes[c])); } } @Benchmark public void test_short(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((short)Math.log(shorts[c])); } } @Benchmark public void test_char(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((char)Math.log(chars[c])); } } @Benchmark public void test_int(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((int)Math.log(ints[c])); } } @Benchmark public void test_float(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((float)Math.log(floats[c])); } } @Benchmark public void test_long(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((long)Math.log(longs[c])); } } @Benchmark public void test_double(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((double)Math.log(doubles[c])); } } @Benchmark public void test_Object(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume((Double) Math.log(objects[c])); } } @Benchmark public void test_Array(Blackhole bh) { for (int c = 0; c < steps; c++) { bh.consume(new Double[] {Math.log(arrays[c][0])}); } } }
4,326
28.040268
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/BlackholeValueBench.java
/* * Copyright (c) 2014, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.Random; import java.util.concurrent.TimeUnit; @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @State(Scope.Thread) public class BlackholeValueBench { // TODO: Revisit Blackhole implementation // This benchmark highlights the problem with current consume code, // which is sensitive to what value we are going to hit inside. // Normally, this is solved with more forks, whereas Blackhole // randomizes the value it matches against. boolean[] array = new boolean[1000]; @Setup public void setup() { Random random = new Random(0); for (int i = 0; i < array.length; i++) { array[i] = random.nextBoolean(); } } @Benchmark public void test(Blackhole bh) { for (boolean b : array) { bh.consume(b); } } }
2,184
34.241935
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/CompilerHintsBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) public class CompilerHintsBench { @Benchmark public void baseI_baseline() { do_Plain(Math.PI); } @Benchmark @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"}) public void baseNI_baseline() { do_Plain(Math.PI); } @Benchmark public void baseI_inline() { do_Inline(Math.PI); } @Benchmark @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"}) public void baseNI_inline() { do_Inline(Math.PI); } @Benchmark public void baseI_dontInline() { do_DontInline(Math.PI); } @Benchmark @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"}) public void baseNI_dontInline() { do_DontInline(Math.PI); } @Benchmark public void baseI_exclude() { do_Exclude(Math.PI); } @Benchmark @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"}) public void baseNI_exclude() { do_Exclude(Math.PI); } private double do_Plain(double x) { return Math.log(x); } @CompilerControl(CompilerControl.Mode.INLINE) private double do_Inline(double x) { return Math.log(x); } @CompilerControl(CompilerControl.Mode.DONT_INLINE) private double do_DontInline(double x) { return Math.log(x); } @CompilerControl(CompilerControl.Mode.EXCLUDE) private double do_Exclude(double x) { return Math.log(x); } }
2,916
27.881188
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/CurrentTimeMillisTimerBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import java.util.concurrent.TimeUnit; @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @Warmup(iterations = 5, time = 1) @Measurement(iterations = 5, time = 1) public class CurrentTimeMillisTimerBench { private long last; @Benchmark public long latency() { return System.currentTimeMillis(); } @Benchmark public long granularity() { long lst = last; long cur; do { cur = System.currentTimeMillis(); } while (cur == lst); last = cur; return cur; } }
1,881
32.607143
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/EmptyBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Warmup; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) public class EmptyBench { @Benchmark public void empty() { } }
1,849
37.541667
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/LevelInvocationBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) public class LevelInvocationBench { @State(Scope.Benchmark) public static class BenchmarkSetup { @Setup(Level.Invocation) public void setup() {} } @State(Scope.Benchmark) public static class BenchmarkTeardown { @TearDown(Level.Invocation) public void tearDown() {} } @State(Scope.Thread) public static class ThreadSetup { @Setup(Level.Invocation) public void setup() {} } @State(Scope.Thread) public static class ThreadTeardown { @TearDown(Level.Invocation) public void tearDown() {} } @State(Scope.Group) public static class GroupSetup { @Setup(Level.Invocation) public void setup() {} } @State(Scope.Group) public static class GroupTeardown { @TearDown(Level.Invocation) public void tearDown() {} } @Benchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) public void raw() { // do nothing } @Benchmark public void benchmark_setup(BenchmarkSetup g) {} @Benchmark public void benchmark_teardown(BenchmarkTeardown g) {} @Benchmark @Group("group_setup") public void group_setup_1(GroupSetup g) {} @Benchmark @Group("group_setup") public void group_setup_2(GroupSetup g) {} @Benchmark @Group("group_teardown") public void group_teardown_1(GroupTeardown g) {} @Benchmark @Group("group_teardown") public void group_teardown_2(GroupTeardown g) {} @Benchmark public void thread_setup(ThreadSetup g) {} @Benchmark public void thread_teardown(ThreadTeardown g) {} }
3,168
28.342593
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/LevelIterationBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) public class LevelIterationBench { @State(Scope.Benchmark) public static class BenchmarkSetup { @Setup(Level.Iteration) public void setup() {} } @State(Scope.Benchmark) public static class BenchmarkTeardown { @TearDown(Level.Iteration) public void tearDown() {} } @State(Scope.Thread) public static class ThreadSetup { @Setup(Level.Iteration) public void setup() {} } @State(Scope.Thread) public static class ThreadTeardown { @TearDown(Level.Iteration) public void tearDown() {} } @State(Scope.Group) public static class GroupSetup { @Setup(Level.Iteration) public void setup() {} } @State(Scope.Group) public static class GroupTeardown { @TearDown(Level.Iteration) public void tearDown() {} } @Benchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) public void raw() { // do nothing } @Benchmark public void benchmark_setup(BenchmarkSetup g) {} @Benchmark public void benchmark_teardown(BenchmarkTeardown g) {} @Benchmark @Group("group_setup") public void group_setup_1(GroupSetup g) {} @Benchmark @Group("group_setup") public void group_setup_2(GroupSetup g) {} @Benchmark @Group("group_teardown") public void group_teardown_1(GroupTeardown g) {} @Benchmark @Group("group_teardown") public void group_teardown_2(GroupTeardown g) {} @Benchmark public void thread_setup(ThreadSetup g) {} @Benchmark public void thread_teardown(ThreadTeardown g) {} }
3,161
28.277778
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/LevelTrialBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) public class LevelTrialBench { @State(Scope.Benchmark) public static class BenchmarkSetup { @Setup(Level.Trial) public void setup() {} } @State(Scope.Benchmark) public static class BenchmarkTeardown { @TearDown(Level.Trial) public void tearDown() {} } @State(Scope.Thread) public static class ThreadSetup { @Setup(Level.Trial) public void setup() {} } @State(Scope.Thread) public static class ThreadTeardown { @TearDown(Level.Trial) public void tearDown() {} } @State(Scope.Group) public static class GroupSetup { @Setup(Level.Trial) public void setup() {} } @State(Scope.Group) public static class GroupTeardown { @TearDown(Level.Trial) public void tearDown() {} } @Benchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) public void raw() { // do nothing } @Benchmark public void benchmark_setup(BenchmarkSetup g) {} @Benchmark public void benchmark_teardown(BenchmarkTeardown g) {} @Benchmark @Group("group_setup") public void group_setup_1(GroupSetup g) {} @Benchmark @Group("group_setup") public void group_setup_2(GroupSetup g) {} @Benchmark @Group("group_teardown") public void group_teardown_1(GroupTeardown g) {} @Benchmark @Group("group_teardown") public void group_teardown_2(GroupTeardown g) {} @Benchmark public void thread_setup(ThreadSetup g) {} @Benchmark public void thread_teardown(ThreadTeardown g) {} }
3,133
28.018519
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/NanoTimerBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; import java.util.concurrent.TimeUnit; @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @Warmup(iterations = 5, time = 1) @Measurement(iterations = 5, time = 1) public class NanoTimerBench { private long last; @Benchmark public long latency() { return System.nanoTime(); } @Benchmark public long granularity() { long lst = last; long cur; do { cur = System.nanoTime(); } while (cur == lst); last = cur; return cur; } }
2,175
33.539683
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/RoundTripLatencyBench.java
/* * Copyright (c) 2023, Red Hat, Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.validation.SpinWaitSupport; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.validation.AffinitySupport; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @State(Scope.Thread) public class RoundTripLatencyBench { static final boolean SPINWAIT = Boolean.getBoolean("spinWait"); @Param("-1") int p; @Param("-1") int c; Thread t; volatile boolean ping; @Setup public void setup() { if (c != -1) AffinitySupport.bind(c); t = new Thread(() -> { if (p != -1) AffinitySupport.bind(p); Thread t = Thread.currentThread(); while (!t.isInterrupted()) { while (!ping) { if (SPINWAIT) SpinWaitSupport.onSpinWait(); } ping = false; } }); t.start(); } @TearDown public void tearDown() throws InterruptedException { t.interrupt(); ping = true; t.join(); } @Benchmark public void test() { ping = true; while (ping) { if (SPINWAIT) SpinWaitSupport.onSpinWait(); } } }
2,454
29.308642
76
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/ScoreStabilityBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.SingleShotTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Warmup(iterations = 50) @Measurement(iterations = 50) @Threads(1) @State(Scope.Thread) public class ScoreStabilityBench { @Param("10") private int delay; @Setup(Level.Iteration) public void sleep() throws InterruptedException { TimeUnit.MILLISECONDS.sleep(delay); } @Benchmark public void test() { Blackhole.consumeCPU(1_000_000); } }
1,831
32.925926
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/ThermalRundownBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @State(Scope.Thread) public class ThermalRundownBench { @Benchmark public void test() { Blackhole.consumeCPU(1_000_000); } }
1,587
35.930233
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/ThreadScalingBench.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.benchmarks; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @State(Scope.Thread) public class ThreadScalingBench { @Benchmark public void test() { Blackhole.consumeCPU(1_000_000); } }
1,586
35.906977
79
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/AffinitySupport.java
/* * Copyright (c) 2023, Red Hat, Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation; import com.sun.jna.*; import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.List; public class AffinitySupport { public static boolean isLinux() { return System.getProperty("os.name").toLowerCase().contains("linux"); } public static boolean isSupported() { return isLinux(); } public static void bind(int cpu) { if (isLinux()) { Linux.bind(cpu); } else { throw new IllegalStateException("Not implemented"); } } public static void tryBind() { if (isLinux()) { Linux.tryBind(); } else { throw new IllegalStateException("Not implemented"); } } public static List<String> prepare() { if (isLinux()) { return Linux.prepare(); } else { throw new IllegalStateException("Not implemented"); } } public static void tryInit() { if (isLinux()) { Linux.tryInit(); } } static class Linux { private static volatile CLibrary INSTANCE; private static boolean BIND_TRIED; /* Unpacks the libraries, and replies additional options for forked VMs. */ public static List<String> prepare() { System.setProperty("jnidispatch.preserve", "true"); Native.load("c", CLibrary.class); File file = new File(System.getProperty("jnidispatch.path")); String bootLibraryPath = file.getParent(); // Need to rename the file to the proper name, otherwise JNA would not discover it File proper = new File(bootLibraryPath + '/' + System.mapLibraryName("jnidispatch")); if (!file.renameTo(proper)) { throw new IllegalStateException("Failed to rename " + file + " to " + proper); } return Arrays.asList( "-Djna.nounpack=true", // Should not unpack itself, but use predefined path "-Djna.nosys=true", // Should load from explicit path "-Djna.noclasspath=true", // Should load from explicit path "-Djna.boot.library.path=" + bootLibraryPath, "-Djna.platform.library.path=" + System.getProperty("jna.platform.library.path") ); } public static void tryInit() { if (INSTANCE == null) { synchronized (Linux.class) { if (INSTANCE == null) { INSTANCE = Native.load("c", CLibrary.class); } } } } public static void bind(int cpu) { tryInit(); final cpu_set_t cpuset = new cpu_set_t(); cpuset.set(cpu); set(cpuset); } public static void tryBind() { if (BIND_TRIED) return; synchronized (Linux.class) { if (BIND_TRIED) return; tryInit(); cpu_set_t cs = new cpu_set_t(); get(cs); set(cs); BIND_TRIED = true; } } private static void get(cpu_set_t cpuset) { if (INSTANCE.sched_getaffinity(0, cpu_set_t.SIZE_OF, cpuset) != 0) { throw new IllegalStateException("Failed: " + Native.getLastError()); } } private static void set(cpu_set_t cpuset) { if (INSTANCE.sched_setaffinity(0, cpu_set_t.SIZE_OF, cpuset) != 0) { throw new IllegalStateException("Failed: " + Native.getLastError()); } } interface CLibrary extends Library { int sched_getaffinity(int pid, int size, cpu_set_t cpuset); int sched_setaffinity(int pid, int size, cpu_set_t cpuset); } public static class cpu_set_t extends Structure { private static final int CPUSET_SIZE = 1024; private static final int NCPU_BITS = 8 * NativeLong.SIZE; private static final int SIZE_OF = (CPUSET_SIZE / NCPU_BITS) * NativeLong.SIZE; public NativeLong[] __bits = new NativeLong[CPUSET_SIZE / NCPU_BITS]; public cpu_set_t() { for (int i = 0; i < __bits.length; i++) { __bits[i] = new NativeLong(0); } } public void set(int cpu) { int cIdx = cpu / NCPU_BITS; long mask = 1L << (cpu % NCPU_BITS); NativeLong bit = __bits[cIdx]; bit.setValue(bit.longValue() | mask); } @Override protected List<String> getFieldOrder() { return Collections.singletonList("__bits"); } } } }
6,082
32.240437
100
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/IterationScoresFormatter.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation; import org.openjdk.jmh.infra.BenchmarkParams; import org.openjdk.jmh.infra.IterationParams; import org.openjdk.jmh.results.BenchmarkResult; import org.openjdk.jmh.results.IterationResult; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.format.OutputFormat; import java.io.IOException; import java.io.PrintWriter; import java.util.Collection; public class IterationScoresFormatter implements OutputFormat { private final PrintWriter pw; public IterationScoresFormatter(PrintWriter pw) { this.pw = pw; } @Override public void iteration(BenchmarkParams benchParams, IterationParams params, int iteration) { } @Override public void iterationResult(BenchmarkParams benchParams, IterationParams params, int iteration, IterationResult data) { Result r = data.getPrimaryResult(); pw.println(String.format(" %.2f ± %.2f %s", r.getScore(), r.getScoreError(), r.getScoreUnit())); } @Override public void startBenchmark(BenchmarkParams benchParams) { } @Override public void endBenchmark(BenchmarkResult result) { } @Override public void startRun() { } @Override public void endRun(Collection<RunResult> result) { } @Override public void print(String s) { } @Override public void println(String s) { } @Override public void flush() { } @Override public void close() { } @Override public void verbosePrintln(String s) { } @Override public void write(int b) { } @Override public void write(byte[] b) throws IOException { } }
2,947
25.088496
123
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/Main.java
/* * Copyright (c) 2005, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation; import joptsimple.*; import org.openjdk.jmh.runner.CompilerHints; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.*; import org.openjdk.jmh.util.Utils; import org.openjdk.jmh.util.Version; import org.openjdk.jmh.validation.tests.*; import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] args) throws RunnerException, CommandLineOptionException, IOException { PrintWriter pw = new PrintWriter(System.out, true); pw.println("JMH Core Benchmarks, Validation Tests"); pw.println("----------------------------------------------------------------------------------------------------------"); pw.println(); pw.println("# " + Version.getVersion()); pw.println("# " + Utils.getCurrentJvmVersion()); pw.println("# " + Utils.getCurrentOSVersion()); pw.println(); Utils.reflow(pw, "These tests assess the current benchmarking environment health, including hardware, OS, JVM, and JMH " + "itself. While the failure on these tests does not immediately means the problem with environment, " + "it is instructive to understand and follow up on oddities in these tests.", 80, 2); pw.println(); Utils.reflow(pw, "If you are sharing this report, please share it in full, including the JVM version, OS flavor and version, " + "plus some data on used hardware.", 80, 2); pw.println(); pw.println(" Use -h to get help on available options."); pw.println(); OptionParser parser = new OptionParser(); parser.formatHelpWith(new OptionFormatter()); OptionSpec<Test> optTests = parser.accepts("t", "Test names.") .withRequiredArg().ofType(Test.class).withValuesSeparatedBy(',').describedAs("string") .defaultsTo(Test.values()); OptionSpec<Mode> optMode = parser.accepts("m", "Running mode, one of " + Arrays.toString(Mode.values()) + ".") .withRequiredArg().ofType(Mode.class).describedAs("mode") .defaultsTo(Mode.normal); parser.accepts("h", "Print help."); List<Test> tests; Mode mode; try { OptionSet set = parser.parse(args); if (set.has("h")) { parser.printHelpOn(System.out); return; } tests = set.valuesOf(optTests); mode = set.valueOf(optMode); } catch (OptionException e) { String message = e.getMessage(); Throwable cause = e.getCause(); if (cause instanceof ValueConversionException) { message += ". " + cause.getMessage(); } throw new CommandLineOptionException(message, e); } Options opts = new OptionsBuilder() .detectJvmArgs() .jvmArgsAppend("-Xmx512m", "-Xms512m", "-server") .build(); switch (mode) { case flash: opts = new OptionsBuilder() .parent(opts) .warmupIterations(3) .warmupTime(TimeValue.milliseconds(10)) .measurementIterations(3) .measurementTime(TimeValue.milliseconds(10)) .forks(1) .build(); break; case quick: opts = new OptionsBuilder() .parent(opts) .warmupIterations(3) .warmupTime(TimeValue.milliseconds(100)) .measurementIterations(3) .measurementTime(TimeValue.milliseconds(100)) .forks(3) .build(); break; case normal: opts = new OptionsBuilder() .parent(opts) .warmupIterations(5) .warmupTime(TimeValue.milliseconds(500)) .measurementIterations(5) .measurementTime(TimeValue.milliseconds(500)) .forks(5) .build(); break; case longer: opts = new OptionsBuilder() .parent(opts) .warmupIterations(10) .warmupTime(TimeValue.seconds(1)) .measurementIterations(10) .measurementTime(TimeValue.seconds(1)) .forks(10) .build(); break; default: throw new IllegalStateException(); } for (Test t : tests) { switch (t) { case timing: new TimingMeasurementsTest().runWith(pw, opts); break; case stability: new ScoreStabilityTest().runWith(pw, opts); break; case compiler_hints: new CompilerHintsTest().runWith(pw, opts); break; case thermal: switch (mode) { case flash: new ThermalRundownTest(3).runWith(pw, opts); break; case quick: new ThermalRundownTest(5).runWith(pw, opts); break; case normal: new ThermalRundownTest(18).runWith(pw, opts); break; case longer: new ThermalRundownTest(60).runWith(pw, opts); break; default: throw new IllegalStateException(); } break; case helpers: new HelperMethodsTest().runWith(pw, opts); break; case thread_scale: new ThreadScalingTest().runWith(pw, opts); break; case blackhole_cpu: new BlackholeConsumeCPUTest().runWith(pw, opts); break; case blackhole_single: setBlackholeOpts(BlackholeTestMode.normal); new BlackholeSingleTest(BlackholeTestMode.normal).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.compiler); new BlackholeSingleTest(BlackholeTestMode.compiler).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.full_dontinline); new BlackholeSingleTest(BlackholeTestMode.full_dontinline).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.full); new BlackholeSingleTest(BlackholeTestMode.full).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.normal); break; case blackhole_pipelined: setBlackholeOpts(BlackholeTestMode.normal); new BlackholePipelinedTest(false, BlackholeTestMode.normal).runWith(pw, opts); new BlackholePipelinedTest(true, BlackholeTestMode.normal).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.compiler); new BlackholePipelinedTest(false, BlackholeTestMode.compiler).runWith(pw, opts); new BlackholePipelinedTest(true, BlackholeTestMode.compiler).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.full_dontinline); new BlackholePipelinedTest(false, BlackholeTestMode.full_dontinline).runWith(pw, opts); new BlackholePipelinedTest(true, BlackholeTestMode.full_dontinline).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.full); new BlackholePipelinedTest(false, BlackholeTestMode.full).runWith(pw, opts); new BlackholePipelinedTest(true, BlackholeTestMode.full).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.normal); break; case blackhole_consec: setBlackholeOpts(BlackholeTestMode.normal); new BlackholeConsecutiveTest(BlackholeTestMode.normal).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.compiler); new BlackholeConsecutiveTest(BlackholeTestMode.compiler).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.full_dontinline); new BlackholeConsecutiveTest(BlackholeTestMode.full_dontinline).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.full); new BlackholeConsecutiveTest(BlackholeTestMode.full).runWith(pw, opts); setBlackholeOpts(BlackholeTestMode.normal); break; case roundtrip_latency: new RoundTripLatencyTest(false).runWith(pw, opts); new RoundTripLatencyTest(true).runWith(pw, opts); break; default: throw new IllegalStateException(); } } } public enum Test { timing, compiler_hints, thermal, stability, thread_scale, helpers, blackhole_cpu, blackhole_single, blackhole_pipelined, blackhole_consec, roundtrip_latency, } public enum Mode { flash, quick, normal, longer, } private static void setBlackholeOpts(BlackholeTestMode mode) { switch (mode) { case normal: // Do nothing System.getProperties().remove("jmh.blackhole.mode"); break; case compiler: System.getProperties().setProperty("jmh.blackhole.mode", "COMPILER"); break; case full_dontinline: System.getProperties().setProperty("jmh.blackhole.mode", "FULL_DONTINLINE"); break; case full: System.getProperties().setProperty("jmh.blackhole.mode", "FULL"); break; } try { Field f = CompilerHints.class.getDeclaredField("hintsFile"); f.setAccessible(true); f.set(null, null); } catch (Exception e) { throw new IllegalStateException(e); } } }
12,183
41.15917
129
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/SpinWaitSupport.java
/* * Copyright (c) 2023, Red Hat, Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; public class SpinWaitSupport { // All critical code should fold with C2 compilation. // This provides us with JDK 8 compatibility. static final MethodHandle MH; static { MethodHandle mh; try { mh = MethodHandles.lookup().findStatic(Thread.class, "onSpinWait", MethodType.methodType(void.class)); } catch (NoSuchMethodException | IllegalAccessException e) { mh = null; } MH = mh; } public static boolean available() { return MH != null; } public static void onSpinWait() { if (MH != null) { try { MH.invokeExact(); } catch (Throwable e) { throw new IllegalStateException("Should not happen", e); } } } }
2,143
33.031746
114
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/ValidationTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.validation.tests.BlackholeTestMode; import java.io.PrintWriter; public abstract class ValidationTest { public abstract void runWith(PrintWriter pw, Options parent) throws RunnerException; protected String blackholeModeString(BlackholeTestMode mode) { switch (mode) { case normal: return "DEFAULT"; case compiler: return "COMPILER BLACKHOLE"; case full_dontinline: return "FULL BLACKHOLE, NO INLINE"; case full: return "FULL BLACKHOLE"; default: throw new IllegalStateException("Unknown blackhole mode: " + mode); } } protected void blackholeModeMessage(PrintWriter pw, BlackholeTestMode mode) { switch (mode) { case normal: break; case compiler: org.openjdk.jmh.util.Utils.reflow(pw, "This particular test mode enables the compiler-assisted blackholes. " + "It should provide the most consistent performance across all types. " + "This mode is only available in modern JDKs.", 80, 2); pw.println(); break; case full_dontinline: org.openjdk.jmh.util.Utils.reflow(pw, "This particular test mode omits the compiler-assisted blackholes. " + "It should provide the basic level of safety for all JDKs.", 80, 2); pw.println(); break; case full: org.openjdk.jmh.util.Utils.reflow(pw, "This particular test mode forces the inline of Blackhole methods, and so demolishes two of the layers " + "in defence in depth. If this layer is broken, Blackhole should also survive. If it isn't, then " + "JMH will have to provide more contingencies.", 80, 2); pw.println(); break; default: throw new IllegalStateException("Unknown blackhole mode: " + mode); } } }
3,628
41.694118
131
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/BlackholeConsecutiveTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.benchmarks.BlackholeConsecutiveBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; import java.util.Arrays; public class BlackholeConsecutiveTest extends ValidationTest { private final BlackholeTestMode mode; public BlackholeConsecutiveTest(BlackholeTestMode mode) { this.mode = mode; } @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- BLACKHOLE MERGING TEST (" + blackholeModeString(mode) + ")"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test verifies that calling the Blackhole.consume with the same result is not susceptible for " + "merging. We expect the similar performance across all data types, and the number of consecutive " + "calls. If there are significant differences, this is indicative of Blackhole failure, and it is " + "a serious JMH issue.", 80, 2); pw.println(); blackholeModeMessage(pw, mode); String[] types = new String[] { "boolean", "byte", "short", "char", "int", "float", "long", "double", "Object", }; int[] ss = new int[] {1, 4, 8}; pw.println(" Scores are nanoseconds per Blackhole call."); pw.println(" Trying " + Arrays.toString(ss) + " consecutive Blackhole calls."); pw.println(); pw.printf("%12s", ""); for (int steps : ss) { pw.printf("%20s", steps); } pw.println(); for (String type : types) { pw.printf("%12s", type + ": "); for (int steps : ss) { Options opts = new OptionsBuilder() .parent(parent) .include(BlackholeConsecutiveBench.class.getCanonicalName() + ".test_" + type + "_" + steps) .param("steps", String.valueOf(steps)) .verbosity(VerboseMode.SILENT) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%20s", String.format("%.2f ± %.2f", r.getScore() / steps, r.getScoreError() / steps)); pw.flush(); } pw.println(); } pw.println(); } }
4,067
39.277228
124
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/BlackholeConsumeCPUTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.benchmarks.BlackholeConsumeCPUBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class BlackholeConsumeCPUTest extends ValidationTest { @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- BLACKHOLE CONSUME CPU TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test assesses the Blackhole.consumeCPU performance, that should be linear to " + "the number of tokens. The performance can be slightly different on low token " + "counts. Otherwise, the backoffs with consumeCPU are not reliable. ", 80, 2); pw.println(); pw.println(" Scores are (normalized) nanoseconds per token."); pw.println(); pw.printf("%20s%n", "#Tokens: "); for (int delay : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 500, 1_000, 5_000, 10_000, 50_000, 100_000, 500_000, 1_000_000, 5_000_000, 10_000_000}) { Options opts = new OptionsBuilder() .parent(parent) .include(BlackholeConsumeCPUBench.class.getCanonicalName()) .verbosity(VerboseMode.SILENT) .param("delay", String.valueOf(delay)) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%20s", delay + ": "); pw.flush(); pw.printf("%.2f ± %.2f ns\n", r.getScore() / delay, r.getScoreError() / delay); } pw.println(); } }
3,332
41.730769
105
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/BlackholePipelinedTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.benchmarks.BlackholePipelineBench; import org.openjdk.jmh.benchmarks.BlackholePipelinePayloadBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; import java.util.Arrays; public class BlackholePipelinedTest extends ValidationTest { private final boolean payload; private final BlackholeTestMode mode; public BlackholePipelinedTest(boolean payload, BlackholeTestMode mode) { this.payload = payload; this.mode = mode; } @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- BLACKHOLE PIPELINED TEST" + (payload ? " + REAL PAYLOAD" : "") + " (" + blackholeModeString(mode) + ")"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test shows the Blackhole performance in a loop with a given number of iterations. We should normally " + "see the uniform numbers across most data types and number of iterations. If the numbers are wildly " + "non-uniform across the number of iteration, this is indicative of Blackhole failure, and may point " + "to a serious JMH issue. Scores are nanoseconds per loop iteration.", 80, 2); pw.println(); if (payload) { pw.println(" Real payload is being injected into the benchmark."); pw.println(); } blackholeModeMessage(pw, mode); String[] types = new String[] { "boolean", "byte", "short", "char", "int", "float", "long", "double", "Object", "Array", }; int[] ss = {1, 10, 100, 1_000, 10_000}; pw.println(" Scores are nanoseconds per (normalized) benchmark op."); pw.println(" Trying loops with " + Arrays.toString(ss) + " iterations."); pw.println(); String canonicalName = (payload ? BlackholePipelinePayloadBench.class : BlackholePipelineBench.class).getCanonicalName(); pw.printf("%12s", ""); for (int steps : ss) { pw.printf("%16s", steps); } pw.println(); for (String type : types) { pw.printf("%12s", type + ": "); for (int steps : ss) { Options opts = new OptionsBuilder() .parent(parent) .include(canonicalName + ".test_" + type) .param("steps", String.valueOf(steps)) .verbosity(VerboseMode.SILENT) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%16s", String.format("%.2f ± %.2f", r.getScore() / steps, r.getScoreError() / steps)); pw.flush(); } pw.println(); } pw.println(); } }
4,588
39.254386
135
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/BlackholeSingleTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.benchmarks.BlackholeBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class BlackholeSingleTest extends ValidationTest { private final BlackholeTestMode mode; public BlackholeSingleTest(BlackholeTestMode mode) { this.mode = mode; } @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- BLACKHOLE SINGLE INVOCATION TEST (" + blackholeModeString(mode) + ")"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test shows the Blackhole overheads, when using a single invocation in the method, " + "whether implicitly via return from @Benchmark, or explicitly via consume(). The performance " + "should be the same for implicit and explicit cases, and comparable across all data types. ", 80, 2); pw.println(); blackholeModeMessage(pw, mode); String[] types = new String[] { "boolean", "byte", "short", "char", "int", "float", "long", "double", "Object", "Array", }; String[] modes = {"implicit", "explicit"}; pw.println(" Scores are nanoseconds per benchmark op."); pw.println(); pw.printf("%20s", ""); for (String mode : modes) { pw.printf("%20s", mode); } pw.println(); for (String type : types) { pw.printf("%20s", type + ": "); for (String impl : modes) { Options opts = new OptionsBuilder() .parent(parent) .include(BlackholeBench.class.getCanonicalName() + "." + impl + "_" + type) .verbosity(VerboseMode.SILENT) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.flush(); pw.printf("%20s", String.format("%.2f ± %.2f ns", r.getScore(), r.getScoreError())); } pw.println(); } pw.println(); } }
3,822
38.010204
120
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/BlackholeTestMode.java
/* * Copyright (c) 2020, Red Hat, Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; public enum BlackholeTestMode { normal, compiler, full_dontinline, full, }
1,325
39.181818
76
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/CompilerHintsTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.annotations.CompilerControl; import org.openjdk.jmh.benchmarks.CompilerHintsBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class CompilerHintsTest extends ValidationTest { @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- COMPILER HINTS TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This tests verifies compiler hints are working as expected. Two baseline tests run the workload " + "in inlined and non-inlined regiments. When the workload is inlined, the optimizations should " + "kill the workload body. Compiler hints should successfully survive in both regiments: " + CompilerControl.Mode.INLINE + " should always inline, and " + CompilerControl.Mode.DONT_INLINE + " " + "should always break inlining. " + CompilerControl.Mode.EXCLUDE + " should be neutral to inlining " + "policy completely.", 80, 2); pw.println(); doWith(parent, pw, "baseI_baseline", "Default inline policy"); doWith(parent, pw, "baseI_inline", " + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.INLINE + ")"); doWith(parent, pw, "baseI_dontInline", " + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.DONT_INLINE + ")"); doWith(parent, pw, "baseI_exclude", " + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.EXCLUDE + ")"); pw.println(); doWith(parent, pw, "baseNI_baseline", "Default no inline policy"); doWith(parent, pw, "baseNI_inline", " + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.INLINE + ")"); doWith(parent, pw, "baseNI_dontInline", " + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.DONT_INLINE + ")"); doWith(parent, pw, "baseNI_exclude", " + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.EXCLUDE + ")"); pw.println(); } private void doWith(Options parent, PrintWriter pw, String test, String descr) throws RunnerException { Options opts = new OptionsBuilder() .parent(parent) .include(CompilerHintsBench.class.getCanonicalName() + "." + test + "$") .verbosity(VerboseMode.SILENT) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%50s", descr + ": "); pw.flush(); pw.printf("%.2f \u00b1 %.2f ns\n", r.getScore(), r.getScoreError()); } }
4,386
50.011628
144
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/HelperMethodsTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.benchmarks.EmptyBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class HelperMethodsTest extends ValidationTest { @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- HELPER METHOD TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "These tests show the overheads of using the benchmark methods. Normally, only " + "Level.Invocation helpers should affect the benchmark performance, since " + "other helpers execute outside the benchmark path.", 80, 2); pw.println(); { Options opts = new OptionsBuilder() .parent(parent) .include(EmptyBench.class.getCanonicalName()) .verbosity(VerboseMode.SILENT) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%51s", "running empty benchmark: "); pw.flush(); pw.printf("%.2f \u00b1 %.2f ns\n", r.getScore(), r.getScoreError()); pw.println(); } for (Scope scope : Scope.values()) { for (Level level : Level.values()) { for (String helper : new String[]{"Setup", "TearDown"}) { Options opts = new OptionsBuilder() .parent(parent) .include("Level" + level + "Bench" + "." + scope.name().toLowerCase() + "_" + helper.toLowerCase() + "$") .verbosity(VerboseMode.SILENT) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%20s, %16s, %10s: ", "Scope." + scope, "Level." + level, "@" + helper); pw.flush(); pw.printf("%.2f \u00b1 %.2f ns\n", r.getScore(), r.getScoreError()); } } pw.println(); } pw.println(); } }
3,887
40.806452
133
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/RoundTripLatencyTest.java
/* * Copyright (c) 2023, Red Hat, Inc. 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.benchmarks.RoundTripLatencyBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.util.Utils; import org.openjdk.jmh.validation.AffinitySupport; import org.openjdk.jmh.validation.SpinWaitSupport; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class RoundTripLatencyTest extends ValidationTest { private boolean spinWaitHints; public RoundTripLatencyTest(boolean spinWaitHints) { this.spinWaitHints = spinWaitHints; } @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- ROUND-TRIP LATENCY TEST" + (spinWaitHints ? " (SPIN-WAIT HINTS)" : "")); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test tries to run latency benchmark across the entire system. " + "For many-core systems, it is normal to see large latency variations between CPU threads pairs. " + "This gives the idea how much the tests with communicating threads would differ when scheduled differently.", 80, 2); pw.println(); pw.println(" Scores are nanoseconds per round-trip."); pw.println(" Axes are CPU numbers as presented by OS."); pw.println(); if (!AffinitySupport.isSupported()) { pw.println(" Affinity control is not available on this machine, skipping the test."); pw.println(); return; } if (spinWaitHints && !SpinWaitSupport.available()) { pw.println(" Spin-wait hints are not supported, skipping the test."); pw.println(); return; } Options basic = new OptionsBuilder() .parent(parent) .include(RoundTripLatencyBench.class.getCanonicalName()) .threads(1) .jvmArgsAppend("-Xms512m", "-Xmx512m", "-XX:+AlwaysPreTouch", "-XX:+UseParallelGC", "-XX:+UseNUMA", "-DspinWait=" + spinWaitHints) .verbosity(VerboseMode.SILENT) .build(); int blockSize = 16; int threads = Utils.figureOutHotCPUs(); int blocks = (threads / blockSize); if (blocks*blockSize < threads) blocks++; for (int pBlock = 0; pBlock < blocks; pBlock++) { int fromP = pBlock*blockSize; int toP = Math.min(threads, (pBlock+1)*blockSize); for (int cBlock = 0; cBlock < blocks; cBlock++) { int fromC = cBlock*blockSize; int toC = Math.min(threads, (cBlock+1)*blockSize); pw.printf("%5s ", ""); for (int c = fromC; c < toC; c++) { pw.printf("%5d:", c); } pw.println(); for (int p = fromP; p < toP; p++) { pw.printf("%5d: ", p); for (int c = fromC; c < toC; c++) { if (p == c) { pw.print(" ----,"); continue; } Options opts = new OptionsBuilder() .parent(basic) .param("p", String.valueOf(p)) .param("c", String.valueOf(c)) .build(); Result r = new Runner(opts).runSingle().getPrimaryResult(); pw.print(String.format("%5.0f,", r.getScore())); pw.flush(); } pw.println(); } pw.println(); } } } }
5,197
38.984615
146
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/ScoreStabilityTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.benchmarks.ScoreStabilityBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class ScoreStabilityTest extends ValidationTest { @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- SCORE STABILITY TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test verifies the performance for a large busy benchmark is the same, regardless " + "of the benchmark mode, and delay before the iteration. The performance should be " + "the same across all delay values, and comparable across different benchmark modes. " + "If there is a significant difference on different delay levels, this is usually " + "indicative of power-saving features enabled, making bursty benchmarks unreliable.", 80, 2); pw.println(); pw.println(" Scores are milliseconds per benchmark operation, or the reciprocal to it."); pw.println(" Delays are injected before each iteration, and are measured in milliseconds."); pw.println(); int[] delays = {0, 1, 10, 100, 1000}; pw.printf("%20s", ""); for (int delay : delays) { pw.printf("%16s", delay); } pw.println(); for (Mode m : Mode.values()) { if (m == Mode.All) continue; Result r = null; pw.printf("%20s", m + ": "); for (int delay : delays) { Options opts = new OptionsBuilder() .parent(parent) .mode(m) .include(ScoreStabilityBench.class.getCanonicalName()) .verbosity(VerboseMode.SILENT) .param("delay", String.valueOf(delay)) .build(); RunResult result = new Runner(opts).runSingle(); r = result.getPrimaryResult(); pw.printf("%16s", String.format("%.2f \u00b1 %.2f", r.getScore(), r.getScoreError())); pw.flush(); } pw.println(" " + r.getScoreUnit()); } pw.println(); } }
3,923
41.193548
111
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/ThermalRundownTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.benchmarks.ThermalRundownBench; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.TimeValue; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.IterationScoresFormatter; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class ThermalRundownTest extends ValidationTest { private final int iterations; public ThermalRundownTest(int iterations) { this.iterations = iterations; } @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- THERMAL RUNDOWN TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test tries to heat the machine up, trying to kick in the thermal throttling. If you see the diminishing " + "performance over time, then your system throttles, and many benchmark experiments are unreliable. ", 80, 2); pw.println(); Options opts = new OptionsBuilder() .parent(parent) .include(ThermalRundownBench.class.getCanonicalName()) .warmupIterations(0) .measurementIterations(iterations) .measurementTime(TimeValue.seconds(10)) .threads(Threads.MAX) .forks(1) .verbosity(VerboseMode.SILENT) .build(); new Runner(opts, new IterationScoresFormatter(pw)).runSingle(); pw.println(); } }
3,020
39.28
129
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/ThreadScalingTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.benchmarks.ThreadScalingBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.util.Utils; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; import java.util.SortedSet; import java.util.TreeSet; public class ThreadScalingTest extends ValidationTest { @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- THREAD SCALING TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test verifies the performance when scaling in multiple threads. " + "In " + Mode.Throughput + " mode, the benchmark should scale almost linearly, at least before " + "the number of physical cores is reached. In other modes, the timings for individual ops should " + "stay roughly the same, at least before the number of physical cores is reached. The departure " + "from the expected behavior might be indicative of scheduling irregularities, power saving " + "features being enabled, process affinity enforced in virtualized environments, etc. -- these may " + "potentially disrupt multi-threaded benchmarks correctness.", 80, 2); pw.println(); pw.println(" Scores are relative to a single-threaded case."); pw.println(" Threads are scaled from 1 to the number of hardware threads."); pw.println(); SortedSet<Integer> threads = new TreeSet<>(); int max = Utils.figureOutHotCPUs(); for (int t = max; t > 0; t /= 2) { threads.add(t); } threads.add(1); threads.add(2); pw.printf("%20s", ""); for (int delay : threads) { pw.printf("%16s", delay); } pw.println(); for (Mode m : Mode.values()) { if (m == Mode.All) continue; Result r; pw.printf("%20s", m + ": "); double base = 0.0; double baseError = 0.0; for (int t : threads) { Options opts = new OptionsBuilder() .parent(parent) .mode(m) .include(ThreadScalingBench.class.getCanonicalName()) .verbosity(VerboseMode.SILENT) .threads(t) .build(); RunResult result = new Runner(opts).runSingle(); r = result.getPrimaryResult(); double score = r.getScore(); double error = r.getScoreError(); if (t == 1) { base = score; baseError = error; } // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Simplification // // For f(x, y) = x/y, boldly assuming x and y are independent, // f_err(x, y) = sqrt(x_err^2 + f(x, y)^2 * y_err^2) / y double f = score / base; double f_err = Math.sqrt(Math.pow(error, 2) + Math.pow(f, 2) * Math.pow(baseError, 2)) / base; pw.printf("%16s", String.format("%.2fx \u00b1 %.2fx", f, f_err)); pw.flush(); } pw.println(); } pw.println(); } }
5,012
39.756098
125
java
jmh
jmh-master/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/TimingMeasurementsTest.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.validation.tests; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.benchmarks.CurrentTimeMillisTimerBench; import org.openjdk.jmh.benchmarks.EmptyBench; import org.openjdk.jmh.benchmarks.NanoTimerBench; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.VerboseMode; import org.openjdk.jmh.validation.ValidationTest; import java.io.PrintWriter; public class TimingMeasurementsTest extends ValidationTest { @Override public void runWith(PrintWriter pw, Options parent) throws RunnerException { pw.println("--------- TIMING MEASUREMENTS TEST"); pw.println(); org.openjdk.jmh.util.Utils.reflow(pw, "This test shows the minimal individual timings possible to measure. " + "This normally affects only SampleTime and SingleShot benchmark modes. " + "Throughput/AverageTime tests can do better since they do only a few " + "timestamps before and after the complete iteration.", 80, 2); pw.println(); doNanoTime(pw, parent, "latency", false); doNanoTime(pw, parent, "latency", true); pw.println(); doCurrentTimeMillis(pw, parent, "latency", false); doCurrentTimeMillis(pw, parent, "latency", true); pw.println(); doNanoTime(pw, parent, "granularity", false); doNanoTime(pw, parent, "granularity", true); pw.println(); doCurrentTimeMillis(pw, parent, "granularity", false); doCurrentTimeMillis(pw, parent, "granularity", true); pw.println(); for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; doEmpty(pw, parent, mode, false); } pw.println(); for (Mode mode : Mode.values()) { if (mode == Mode.All) continue; doEmpty(pw, parent, mode, true); } pw.println(); } private void doEmpty(PrintWriter pw, Options parent, Mode mode, boolean max) throws RunnerException { Options opts = new OptionsBuilder() .parent(parent) .include(EmptyBench.class.getCanonicalName()) .verbosity(VerboseMode.SILENT) .threads(max ? Threads.MAX : 1) .mode(mode) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%50s", mode + ", empty benchmark, " + (max ? "max thread" : "one thread") + ": "); pw.flush(); pw.printf("%10.2f \u00b1 %10.2f %s\n", r.getScore(), r.getScoreError(), r.getScoreUnit()); } void doNanoTime(PrintWriter pw, Options parent, String type, boolean max) throws RunnerException { Options opts = new OptionsBuilder() .parent(parent) .include(NanoTimerBench.class.getCanonicalName() + "." + type + "$") .verbosity(VerboseMode.SILENT) .threads(max ? Threads.MAX : 1) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%50s", "nanoTime() " + type + ", " + (max ? "max thread" : "one thread") + ": "); pw.flush(); pw.printf("%10.2f \u00b1 %10.2f ns\n", r.getScore(), r.getScoreError()); } void doCurrentTimeMillis(PrintWriter pw, Options parent, String type, boolean max) throws RunnerException { Options opts = new OptionsBuilder() .parent(parent) .include(CurrentTimeMillisTimerBench.class.getCanonicalName() + "." + type + "$") .verbosity(VerboseMode.SILENT) .threads(max ? Threads.MAX : 1) .build(); RunResult result = new Runner(opts).runSingle(); Result r = result.getPrimaryResult(); pw.printf("%50s", "currentTimeMillis() " + type + ", " + (max ? "max thread" : "one thread") + ": "); pw.flush(); pw.printf("%10.2f \u00b1 %10.2f ns\n", r.getScore(), r.getScoreError()); } }
5,630
38.65493
111
java
jmh
jmh-master/jmh-core-ct/src/test/java/UnnamedPackageTest.java
/* * Copyright (c) 2021, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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. */ import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class UnnamedPackageTest { @Benchmark public void test() { } @Test public void compileTest() { CompileTest.assertFail(getClass(), "Benchmark class should have package other than default."); } }
1,551
37.8
102
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct; import org.junit.Assert; import org.openjdk.jmh.ct.benchmark.PublicStaticBenchmarkTest; import org.openjdk.jmh.ct.benchmark.PublicSynchronizedStaticBenchmarkStateBenchmarkTest; import org.openjdk.jmh.ct.other.GenericReturnTest; import org.openjdk.jmh.ct.other.SwingTest; import org.openjdk.jmh.generators.asm.ASMGeneratorSource; import org.openjdk.jmh.generators.core.BenchmarkGenerator; import org.openjdk.jmh.generators.core.GeneratorSource; import org.openjdk.jmh.generators.reflection.RFGeneratorSource; import org.openjdk.jmh.util.FileUtils; import org.openjdk.jmh.util.JDKVersion; import org.openjdk.jmh.util.Utils; import javax.tools.*; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; import java.util.*; public class CompileTest { private static final String GENERATOR_TYPE = System.getProperty("jmh.ct.generator", "notset"); private static final String SRC_PREFIX = "SRC: "; public static void assertFail(Class<?> klass) { InMemoryGeneratorDestination destination = new InMemoryGeneratorDestination(); boolean success = doTest(klass, destination); if (success) { Assert.fail("Should have failed."); } } public static void assertFail(Class<?> klass, String error) { InMemoryGeneratorDestination destination = new InMemoryGeneratorDestination(); boolean success = doTest(klass, destination); if (success) { Assert.fail("Should have failed."); } List<String> testErrors = new ArrayList<>(); boolean contains = false; for (String e : destination.getErrors()) { if (!e.startsWith(SRC_PREFIX)) { testErrors.add(e); contains |= e.contains(error); } System.err.println(e); } Assert.assertTrue("Failure message should contain \"" + error + "\", but was \"" + testErrors + "\"", contains); } public static void assertOK(Class<?> klass) { InMemoryGeneratorDestination destination = new InMemoryGeneratorDestination(); boolean success = doTest(klass, destination); if (!success) { for (String e : destination.getErrors()) { System.err.println(e); } Assert.fail("Should have passed."); } } private static boolean doTest(Class<?> klass, InMemoryGeneratorDestination destination) { if (GENERATOR_TYPE.equalsIgnoreCase("reflection")) { RFGeneratorSource source = new RFGeneratorSource(); source.processClasses(klass); return doTestOther(klass, source, destination); } else if (GENERATOR_TYPE.equalsIgnoreCase("asm")) { ASMGeneratorSource source = new ASMGeneratorSource(); String name = "/" + klass.getCanonicalName().replaceAll("\\.", "/") + ".class"; try { source.processClass(klass.getResourceAsStream(name)); } catch (IOException e) { throw new IllegalStateException(name, e); } return doTestOther(klass, source, destination); } else if (GENERATOR_TYPE.equalsIgnoreCase("annprocess")) { return doTestAnnprocess(klass, destination); } else throw new IllegalStateException("Unhandled compile test generator: " + GENERATOR_TYPE); } private static Collection<String> javacOptions(boolean annProc, Class<?> klass) { Collection<String> result = new ArrayList<>(); if (!annProc) { result.add("-proc:none"); } // These tests print warnings (as designed), so -Werror fails. boolean noWerror = klass.equals(SwingTest.class); if (!noWerror) { result.add("-Werror"); } // These tests fail when generated code references the static target // through the instance. boolean noStatic = klass.equals(GenericReturnTest.class) || klass.equals(PublicStaticBenchmarkTest.class) || klass.equals(PublicSynchronizedStaticBenchmarkStateBenchmarkTest.class); // JDK 17 introduces a new warning about unnecessary strictfp use. boolean noStrictFPChecks = JDKVersion.parseMajor(System.getProperty("java.version")) >= 17; result.add("-Xlint:all" + (annProc ? ",-processing" : "") + (noStatic ? ",-static" : "") + (noStrictFPChecks ? ",-strictfp" : "")); return result; } public static boolean doTestOther(Class<?> klass, GeneratorSource source, InMemoryGeneratorDestination destination) { BenchmarkGenerator gen = new BenchmarkGenerator(); gen.generate(source, destination); gen.complete(source, destination); if (destination.hasErrors()) { return false; } DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); setupClassOutput(fm); Collection<JavaSourceFromString> sources = new ArrayList<>(); for (Map.Entry<String, String> e : destination.getClasses().entrySet()) { sources.add(new JavaSourceFromString(e.getKey(), e.getValue())); } JavaCompiler.CompilationTask task = javac.getTask(null, fm, diagnostics, javacOptions(false, klass), null, sources); boolean success = task.call(); if (!success) { for (JavaSourceFromString src : sources) { destination.printError(SRC_PREFIX + src.getCharContent(false).toString()); } for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { destination.printError(diagnostic.getKind() + " at line " + diagnostic.getLineNumber() + ": " + diagnostic.getMessage(null)); } } return success; } private static boolean doTestAnnprocess(Class<?> klass, InMemoryGeneratorDestination destination) { DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); setupClassOutput(fm); String name = "/" + klass.getCanonicalName().replaceAll("\\.", "/") + ".java"; String shortName = klass.getName(); InputStream stream = klass.getResourceAsStream(name); Assert.assertNotNull(name + " is not found", stream); try { Collection<String> lines = FileUtils.readAllLines(new InputStreamReader(stream)); String file = Utils.join(lines, "\n"); Collection<JavaSourceFromString> sources = Collections.singleton(new JavaSourceFromString(shortName, file)); JavaCompiler.CompilationTask task = javac.getTask(null, fm, diagnostics, javacOptions(true, klass), null, sources); boolean success = task.call(); if (!success) { for (JavaSourceFromString src : sources) { destination.printError(SRC_PREFIX + src.getCharContent(false).toString()); } for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { destination.printError(diagnostic.getKind() + " at line " + diagnostic.getLineNumber() + ": " + diagnostic.getMessage(null)); } } return success; } catch (IOException e) { return false; } } private static void setupClassOutput(StandardJavaFileManager fm) { try { File tmp = File.createTempFile("jmh-core-ct", "temp"); if (!tmp.delete()) { throw new IOException("Cannot delete temp file: " + tmp); } if (!tmp.mkdirs()) { throw new IOException("Cannot create temp dir: " + tmp); } tmp.deleteOnExit(); fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(tmp)); } catch (IOException e) { Assert.fail(e.getMessage()); } } public static class JavaSourceFromString extends SimpleJavaFileObject { final String code; JavaSourceFromString(String name, String code) { super(URI.create("string:///" + name.replace('.', '/') + JavaFileObject.Kind.SOURCE.extension), JavaFileObject.Kind.SOURCE); this.code = code; } @Override public CharSequence getCharContent(boolean iee) { return code; } } }
10,024
39.918367
145
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/InMemoryGeneratorDestination.java
/* * Copyright (c) 2014, 2015, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct; import org.openjdk.jmh.generators.core.GeneratorDestination; import org.openjdk.jmh.generators.core.MetadataInfo; import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class InMemoryGeneratorDestination implements GeneratorDestination { private final List<String> errors = new ArrayList<>(); private final List<String> warnings = new ArrayList<>(); private final List<String> infos = new ArrayList<>(); private final Map<String, StringWriter> classBodies = new HashMap<>(); private final Map<String, ByteArrayOutputStream> resourceBodies = new HashMap<>(); @Override public OutputStream newResource(String resourcePath) throws IOException { ByteArrayOutputStream sw = new ByteArrayOutputStream(); resourceBodies.put(resourcePath, sw); return sw; } @Override public InputStream getResource(String resourcePath) throws IOException { ByteArrayOutputStream sw = resourceBodies.get(resourcePath); if (sw == null) { throw new IOException("Does not exist: " + resourcePath); } return new ByteArrayInputStream(sw.toByteArray()); } @Override public Writer newClass(String className, String originatingClassName) throws IOException { StringWriter sw = new StringWriter(); classBodies.put(className, sw); return new PrintWriter(sw, true); } @Override public void printError(String message) { errors.add(message); } @Override public void printError(String message, MetadataInfo element) { errors.add(message); } @Override public void printError(String message, Throwable throwable) { errors.add(message + ":\n" + throwable.toString()); } public boolean hasErrors() { return !errors.isEmpty(); } public List<String> getErrors() { return errors; } @Override public void printWarning(String message) { warnings.add(message); } @Override public void printWarning(String message, MetadataInfo element) { warnings.add(message); } @Override public void printWarning(String message, Throwable throwable) { warnings.add(message + ":\n" + throwable.toString()); } public boolean hasWarnings() { return !warnings.isEmpty(); } public List<String> getWarnings() { return warnings; } public Map<String, String> getClasses() { Map<String, String> result = new HashMap<>(); for (Map.Entry<String, StringWriter> e : classBodies.entrySet()) { result.put(e.getKey(), e.getValue().toString()); } return result; } public Map<String, String> getResources() { Map<String, String> result = new HashMap<>(); for (Map.Entry<String, ByteArrayOutputStream> e : resourceBodies.entrySet()) { try { result.put(e.getKey(), e.getValue().toString("UTF-8")); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } } return result; } @Override public void printNote(String message) { infos.add(message); } public boolean hasNotes() { return !infos.isEmpty(); } public List<String> getNotes() { return infos; } }
4,656
30.466216
94
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/BenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class BenchmarkTest { @Benchmark void test() { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,532
33.840909
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicAbstractBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public abstract class PublicAbstractBenchmarkTest { @Benchmark public abstract void test(); @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,563
36.238095
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PublicBenchmarkTest { @Benchmark public void test() { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,543
34.090909
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicStaticBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PublicStaticBenchmarkTest { @Benchmark public static void test() { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,556
34.386364
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicSynchronizedBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PublicSynchronizedBenchmarkTest { @Benchmark public synchronized void test() { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,570
34.704545
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicSynchronizedStateBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.ct.CompileTest; @State(Scope.Benchmark) public class PublicSynchronizedStateBenchmarkTest { @Benchmark public synchronized void test() { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,681
34.787234
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicSynchronizedStaticBenchmarkStateBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.ct.CompileTest; @State(Scope.Benchmark) public class PublicSynchronizedStaticBenchmarkStateBenchmarkTest { @Benchmark public static synchronized void test() { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,703
35.255319
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicSynchronizedStaticBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PublicSynchronizedStaticBenchmarkTest { @Benchmark public static synchronized void test() { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "enclosing class is annotated with @State"); } }
1,627
36
92
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/PublicSynchronizedStaticThreadStateBenchmarkTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.ct.CompileTest; @State(Scope.Thread) public class PublicSynchronizedStaticThreadStateBenchmarkTest { @Benchmark public static synchronized void test() { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "@State(Scope.Benchmark)"); } }
1,726
35.744681
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/ArgumentListAmbiguityTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; import org.openjdk.jmh.infra.Blackhole; public class ArgumentListAmbiguityTest { @Benchmark public void test() { } @Benchmark public void test(Blackhole bh) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "uniquely named method"); } }
1,681
32.64
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/BenchmarkParamsTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; import org.openjdk.jmh.infra.BenchmarkParams; public class BenchmarkParamsTest { @Benchmark public void test(BenchmarkParams benchmarkParams) { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,625
35.133333
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/BlackholeTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; import org.openjdk.jmh.infra.Blackhole; public class BlackholeTest { @Benchmark public void test(Blackhole bh) { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,594
34.444444
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/ControlTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; import org.openjdk.jmh.infra.Control; public class ControlTest { @Benchmark public void test(Control cnt) { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,589
34.333333
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/IterationParamsTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; import org.openjdk.jmh.infra.IterationParams; public class IterationParamsTest { @Benchmark public void test(IterationParams params) { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,616
34.933333
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/NoStateTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class NoStateTest { public static class S {} @Benchmark public void test(S s) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,575
33.26087
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/ObjectArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class ObjectArrayTest { @Benchmark public void test(Object[] args) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,559
34.454545
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/ObjectTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class ObjectTest { @Benchmark public void test(Object args) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,552
34.295455
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/StateTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.ct.CompileTest; public class StateTest { @State(Scope.Benchmark) public static class S {} @Benchmark public void test(S s) { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,683
33.367347
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/StringArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class StringArrayTest { @Benchmark public void test(String[] args) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,559
34.454545
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/StringTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class StringTest { @Benchmark public void test(String args) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass()); } }
1,552
34.295455
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimBooleanArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimBooleanArrayTest { @Benchmark public void test(boolean[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,599
35.363636
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimBooleanTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimBooleanTest { @Benchmark public void test(boolean v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,592
35.204545
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimByteArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimByteArrayTest { @Benchmark public void test(byte[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,593
35.227273
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimByteTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimByteTest { @Benchmark public void test(byte v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,586
35.068182
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimCharArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimCharArrayTest { @Benchmark public void test(char[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,593
35.227273
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimCharTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimCharTest { @Benchmark public void test(char v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,586
35.068182
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimDoubleArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimDoubleArrayTest { @Benchmark public void test(double[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,597
35.318182
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimDoubleTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimDoubleTest { @Benchmark public void test(double v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,590
35.159091
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimFloatArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimFloatArrayTest { @Benchmark public void test(float[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,595
35.272727
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimFloatTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimFloatTest { @Benchmark public void test(float v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,588
35.113636
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimIntArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimIntArrayTest { @Benchmark public void test(int[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,591
35.181818
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimIntTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimIntTest { @Benchmark public void test(int v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,584
35.022727
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimLongArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimLongArrayTest { @Benchmark public void test(long[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,593
35.227273
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimLongTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimLongTest { @Benchmark public void test(long v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,586
35.068182
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimShortArrayTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimShortArrayTest { @Benchmark public void test(short[] v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,595
35.272727
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/prims/PrimShortTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.benchmark.args.prims; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.ct.CompileTest; public class PrimShortTest { @Benchmark public void test(short v) { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Method parameters should be"); } }
1,588
35.113636
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/blackhole/BlackholeTypesTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.blackhole; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.ct.CompileTest; import org.openjdk.jmh.infra.Blackhole; @State(Scope.Thread) @BenchmarkMode(Mode.All) public class BlackholeTypesTest { public byte b; public boolean bool; public char c; public short s; public int i; public long l; public float f; public double d; public Object o; public Object[] os; @Benchmark public void baseline() { // do nothing } @Benchmark public byte implicit_testByte() { return b; } @Benchmark public boolean implicit_testBoolean() { return bool; } @Benchmark public char implicit_testChar() { return c; } @Benchmark public int implicit_testInt() { return i; } @Benchmark public long implicit_testLong() { return l; } @Benchmark public float implicit_testFloat() { return f; } @Benchmark public double implicit_testDouble() { return d; } @Benchmark public Object implicit_testObject() { return o; } @Benchmark public Object[] implicit_testArray() { return os; } @Benchmark public void explicit_testByte(Blackhole bh) { bh.consume(b); } @Benchmark public void explicit_testBoolean(Blackhole bh) { bh.consume(bool); } @Benchmark public void explicit_testChar(Blackhole bh) { bh.consume(c); } @Benchmark public void explicit_testInt(Blackhole bh) { bh.consume(i); } @Benchmark public void explicit_testLong(Blackhole bh) { bh.consume(l); } @Benchmark public void explicit_testFloat(Blackhole bh) { bh.consume(f); } @Benchmark public void explicit_testDouble(Blackhole bh) { bh.consume(d); } @Benchmark public void explicit_testObject(Blackhole bh) { bh.consume(o); } @Benchmark public void explicit_testArray(Blackhole bh) { bh.consume(os); } @Test public void test() { CompileTest.assertOK(this.getClass()); } }
3,620
22.822368
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/collisions/CollisionTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.collisions; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.ct.CompileTest; @BenchmarkMode(Mode.All) public class CollisionTest { @Benchmark @Group("same") @Warmup(iterations = 1) public void g1() { } @Benchmark @Group("same") @Warmup(iterations = 5) public void g2() { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Colliding annotations"); } }
1,904
31.844828
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/collisions/NoCollisionTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.collisions; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.ct.CompileTest; @BenchmarkMode(Mode.All) public class NoCollisionTest { @Benchmark @Group("same") @Warmup(iterations = 1) public void g1() { } @Benchmark @Group("same") @Warmup(iterations = 1) public void g2() { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,879
31.413793
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/collisions/SuperCollisionTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.collisions; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.ct.CompileTest; @Warmup(iterations = 1) @BenchmarkMode(Mode.All) public class SuperCollisionTest { @Benchmark @Group("same") // inherited @Warmup(iterations = 1) public void g1() { } @Benchmark @Group("same") @Warmup(iterations = 5) public void g2() { } @Test public void compileTest() { CompileTest.assertFail(this.getClass(), "Colliding annotations"); } }
1,946
32
79
java
jmh
jmh-master/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/collisions/SuperNoCollisionTest.java
/* * Copyright (c) 2005, 2014, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 org.openjdk.jmh.ct.collisions; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Group; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.ct.CompileTest; @Warmup(iterations = 1) @BenchmarkMode(Mode.All) public class SuperNoCollisionTest { @Benchmark @Group("same") @Warmup(iterations = 1) public void g1() { } @Benchmark @Group("same") @Warmup(iterations = 1) public void g2() { } @Test public void compileTest() { CompileTest.assertOK(this.getClass()); } }
1,908
31.355932
79
java