# HG changeset patch # User amurillo # Date 1424105260 28800 # Node ID e70dcf797a33a83315b949059c613c23d430ce05 # Parent 7a1ceff4aea22915534240de48ba559536d0a801# Parent 67b9b02c13fe9e184883fe5fd299f834fc66a741 Merge diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/make/lib/Lib-jdk.runtime.gmk --- a/jdk/make/lib/Lib-jdk.runtime.gmk Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/make/lib/Lib-jdk.runtime.gmk Mon Feb 16 08:47:40 2015 -0800 @@ -59,37 +59,3 @@ TARGETS += $(BUILD_LIBUNPACK) ################################################################################ - -LIBJSDT_SRC := $(JDK_TOPDIR)/src/jdk.runtime/share/native/libjsdt \ - $(JDK_TOPDIR)/src/jdk.runtime/$(OPENJDK_TARGET_OS_TYPE)/native/libjsdt - -$(eval $(call SetupNativeCompilation,BUILD_LIBJSDT, \ - LIBRARY := jsdt, \ - OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ - SRC := $(LIBJSDT_SRC), \ - LANG := C, \ - OPTIMIZATION := LOW, \ - CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) \ - $(addprefix -I, $(LIBJSDT_SRC)) \ - $(LIBJAVA_HEADER_FLAGS) \ - -I$(SUPPORT_OUTPUTDIR)/headers/jdk.runtime, \ - MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjsdt/mapfile-vers, \ - LDFLAGS := $(LDFLAGS_JDKLIB) \ - $(call SET_SHARED_LIBRARY_ORIGIN), \ - LDFLAGS_SUFFIX_linux := $(LIBDL), \ - LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX) $(LIBDL), \ - LDFLAGS_SUFFIX_macosx := $(LIBDL), \ - LDFLAGS_SUFFIX_solaris := -lc, \ - VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ - RC_FLAGS := $(RC_FLAGS) \ - -D "JDK_FNAME=jsdt.dll" \ - -D "JDK_INTERNAL_NAME=jsdt" \ - -D "JDK_FTYPE=0x2L", \ - OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjsdt, \ - DEBUG_SYMBOLS := true)) - -$(BUILD_LIBJSDT): $(call FindLib, java.base, java) - -TARGETS += $(BUILD_LIBJSDT) - -################################################################################ diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java Mon Feb 16 08:47:40 2015 -0800 @@ -31,7 +31,6 @@ import sun.invoke.util.VerifyAccess; import static java.lang.invoke.MethodHandleNatives.Constants.*; import static java.lang.invoke.LambdaForm.*; -import static java.lang.invoke.LambdaForm.BasicType.*; import static java.lang.invoke.MethodTypeForm.*; import static java.lang.invoke.MethodHandleStatics.*; import java.lang.ref.WeakReference; @@ -693,4 +692,10 @@ } } } + + @Override + void customize() { + assert(form.customized == null); + // No need to customize DMHs. + } } diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Mon Feb 16 08:47:40 2015 -0800 @@ -56,9 +56,11 @@ private static final String OBJ = "java/lang/Object"; private static final String OBJARY = "[Ljava/lang/Object;"; + private static final String MH_SIG = "L" + MH + ";"; private static final String LF_SIG = "L" + LF + ";"; private static final String LFN_SIG = "L" + LFN + ";"; private static final String LL_SIG = "(L" + OBJ + ";)L" + OBJ + ";"; + private static final String LLV_SIG = "(L" + OBJ + ";L" + OBJ + ";)V"; private static final String CLL_SIG = "(L" + CLS + ";L" + OBJ + ";)L" + OBJ + ";"; /** Name of its super class*/ @@ -616,6 +618,15 @@ return g.loadMethod(g.generateCustomizedCodeBytes()); } + /** Generates code to check that actual receiver and LambdaForm matches */ + private boolean checkActualReceiver() { + // Expects MethodHandle on the stack and actual receiver MethodHandle in slot #0 + mv.visitInsn(Opcodes.DUP); + mv.visitVarInsn(Opcodes.ALOAD, localsMap[0]); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, MHI, "assertSame", LLV_SIG, false); + return true; + } + /** * Generate an invoker method for the passed {@link LambdaForm}. */ @@ -635,6 +646,16 @@ mv.visitAnnotation("Ljava/lang/invoke/DontInline;", true); } + if (lambdaForm.customized != null) { + // Since LambdaForm is customized for a particular MethodHandle, it's safe to substitute + // receiver MethodHandle (at slot #0) with an embedded constant and use it instead. + // It enables more efficient code generation in some situations, since embedded constants + // are compile-time constants for JIT compiler. + mv.visitLdcInsn(constantPlaceholder(lambdaForm.customized)); + mv.visitTypeInsn(Opcodes.CHECKCAST, MH); + assert(checkActualReceiver()); // expects MethodHandle on top of the stack + mv.visitVarInsn(Opcodes.ASTORE, localsMap[0]); + } // iterate over the form's names, generating bytecode instructions for each // start iterating at the first name following the arguments diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/Invokers.java Mon Feb 16 08:47:40 2015 -0800 @@ -247,6 +247,7 @@ int nameCursor = OUTARG_LIMIT; final int MTYPE_ARG = customized ? -1 : nameCursor++; // might be last in-argument final int CHECK_TYPE = nameCursor++; + final int CHECK_CUSTOM = (CUSTOMIZE_THRESHOLD >= 0) ? nameCursor++ : -1; final int LINKER_CALL = nameCursor++; MethodType invokerFormType = mtype.invokerType(); if (isLinker) { @@ -279,6 +280,9 @@ // mh.invokeGeneric(a*):R => checkGenericType(mh, TYPEOF(a*:R)).invokeBasic(a*) outArgs[0] = names[CHECK_TYPE]; } + if (CHECK_CUSTOM != -1) { + names[CHECK_CUSTOM] = new Name(NF_checkCustomized, names[CALL_MH]); + } names[LINKER_CALL] = new Name(outCallType, outArgs); lform = new LambdaForm(debugName, INARG_LIMIT, names); if (isLinker) @@ -386,11 +390,32 @@ return ((CallSite)site).getTarget(); } + /*non-public*/ static + @ForceInline + void checkCustomized(Object o) { + MethodHandle mh = (MethodHandle)o; + if (mh.form.customized == null) { + maybeCustomize(mh); + } + } + + /*non-public*/ static + @DontInline + void maybeCustomize(MethodHandle mh) { + byte count = mh.customizationCount; + if (count >= CUSTOMIZE_THRESHOLD) { + mh.customize(); + } else { + mh.customizationCount = (byte)(count+1); + } + } + // Local constant functions: private static final NamedFunction NF_checkExactType, NF_checkGenericType, - NF_getCallSiteTarget; + NF_getCallSiteTarget, + NF_checkCustomized; static { try { NamedFunction nfs[] = { @@ -399,7 +424,9 @@ NF_checkGenericType = new NamedFunction(Invokers.class .getDeclaredMethod("checkGenericType", Object.class, Object.class)), NF_getCallSiteTarget = new NamedFunction(Invokers.class - .getDeclaredMethod("getCallSiteTarget", Object.class)) + .getDeclaredMethod("getCallSiteTarget", Object.class)), + NF_checkCustomized = new NamedFunction(Invokers.class + .getDeclaredMethod("checkCustomized", Object.class)) }; for (NamedFunction nf : nfs) { // Each nf must be statically invocable or we get tied up in our bootstraps. diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Mon Feb 16 08:47:40 2015 -0800 @@ -120,12 +120,14 @@ final int arity; final int result; final boolean forceInline; + final MethodHandle customized; @Stable final Name[] names; final String debugName; MemberName vmentry; // low-level behavior, or null if not yet prepared private boolean isCompiled; - volatile Object transformCache; // managed by LambdaFormEditor + // Either a LambdaForm cache (managed by LambdaFormEditor) or a link to uncustomized version (for customized LF) + volatile Object transformCache; public static final int VOID_RESULT = -1, LAST_RESULT = -2; @@ -244,16 +246,17 @@ LambdaForm(String debugName, int arity, Name[] names, int result) { - this(debugName, arity, names, result, true); + this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null); } LambdaForm(String debugName, - int arity, Name[] names, int result, boolean forceInline) { + int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) { assert(namesOK(arity, names)); this.arity = arity; this.result = fixResult(result, names); this.names = names.clone(); this.debugName = fixDebugName(debugName); this.forceInline = forceInline; + this.customized = customized; int maxOutArity = normalize(); if (maxOutArity > MethodType.MAX_MH_INVOKER_ARITY) { // Cannot use LF interpreter on very high arity expressions. @@ -263,21 +266,21 @@ } LambdaForm(String debugName, int arity, Name[] names) { - this(debugName, arity, names, LAST_RESULT, true); + this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null); } LambdaForm(String debugName, int arity, Name[] names, boolean forceInline) { - this(debugName, arity, names, LAST_RESULT, forceInline); + this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null); } LambdaForm(String debugName, Name[] formals, Name[] temps, Name result) { this(debugName, - formals.length, buildNames(formals, temps, result), LAST_RESULT, true); + formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null); } LambdaForm(String debugName, Name[] formals, Name[] temps, Name result, boolean forceInline) { this(debugName, - formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline); + formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null); } private static Name[] buildNames(Name[] formals, Name[] temps, Name result) { @@ -291,10 +294,6 @@ } private LambdaForm(String sig) { - this(sig, true); - } - - private LambdaForm(String sig, boolean forceInline) { // Make a blank lambda form, which returns a constant zero or null. // It is used as a template for managing the invocation of similar forms that are non-empty. // Called only from getPreparedForm. @@ -303,7 +302,8 @@ this.result = (signatureReturn(sig) == V_TYPE ? -1 : arity); this.names = buildEmptyNames(arity, sig); this.debugName = "LF.zero"; - this.forceInline = forceInline; + this.forceInline = true; + this.customized = null; assert(nameRefsAreLegal()); assert(isEmpty()); assert(sig.equals(basicTypeSignature())) : sig + " != " + basicTypeSignature(); @@ -375,6 +375,31 @@ return true; } + /** Customize LambdaForm for a particular MethodHandle */ + LambdaForm customize(MethodHandle mh) { + LambdaForm customForm = new LambdaForm(debugName, arity, names, result, forceInline, mh); + if (COMPILE_THRESHOLD > 0 && isCompiled) { + // If shared LambdaForm has been compiled, compile customized version as well. + customForm.compileToBytecode(); + } + customForm.transformCache = this; // LambdaFormEditor should always use uncustomized form. + return customForm; + } + + /** Get uncustomized flavor of the LambdaForm */ + LambdaForm uncustomize() { + if (customized == null) { + return this; + } + assert(transformCache != null); // Customized LambdaForm should always has a link to uncustomized version. + LambdaForm uncustomizedForm = (LambdaForm)transformCache; + if (COMPILE_THRESHOLD > 0 && isCompiled) { + // If customized LambdaForm has been compiled, compile uncustomized version as well. + uncustomizedForm.compileToBytecode(); + } + return uncustomizedForm; + } + /** Renumber and/or replace params so that they are interned and canonically numbered. * @return maximum argument list length among the names (since we have to pass over them anyway) */ @@ -417,8 +442,8 @@ for (int i = arity; i < names.length; i++) { names[i].internArguments(); } - assert(nameRefsAreLegal()); } + assert(nameRefsAreLegal()); return maxOutArity; } diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java Mon Feb 16 08:47:40 2015 -0800 @@ -51,7 +51,10 @@ static LambdaFormEditor lambdaFormEditor(LambdaForm lambdaForm) { // TO DO: Consider placing intern logic here, to cut down on duplication. // lambdaForm = findPreexistingEquivalent(lambdaForm) - return new LambdaFormEditor(lambdaForm); + + // Always use uncustomized version for editing. + // It helps caching and customized LambdaForms reuse transformCache field to keep a link to uncustomized version. + return new LambdaFormEditor(lambdaForm.uncustomize()); } /** A description of a cached transform, possibly associated with the result of the transform. diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Mon Feb 16 08:47:40 2015 -0800 @@ -434,6 +434,8 @@ // form is not private so that invokers can easily fetch it /*private*/ MethodHandle asTypeCache; // asTypeCache is not private so that invokers can easily fetch it + /*non-public*/ byte customizationCount; + // customizationCount should be accessible from invokers /** * Reports the type of this method handle. @@ -454,9 +456,9 @@ type.getClass(); // explicit NPE form.getClass(); // explicit NPE this.type = type; - this.form = form; + this.form = form.uncustomize(); - form.prepare(); // TO DO: Try to delay this step until just before invocation. + this.form.prepare(); // TO DO: Try to delay this step until just before invocation. } /** @@ -1425,12 +1427,24 @@ */ /*non-public*/ void updateForm(LambdaForm newForm) { + assert(newForm.customized == null || newForm.customized == this); if (form == newForm) return; newForm.prepare(); // as in MethodHandle. UNSAFE.putObject(this, FORM_OFFSET, newForm); UNSAFE.fullFence(); } + /** Craft a LambdaForm customized for this particular MethodHandle */ + /*non-public*/ + void customize() { + if (form.customized == null) { + LambdaForm newForm = form.customize(this); + updateForm(newForm); + } else { + assert(form.customized == this); + } + } + private static final long FORM_OFFSET; static { try { diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Mon Feb 16 08:47:40 2015 -0800 @@ -597,6 +597,7 @@ static final NamedFunction NF_checkSpreadArgument; static final NamedFunction NF_guardWithCatch; static final NamedFunction NF_throwException; + static final NamedFunction NF_profileBoolean; static final MethodHandle MH_castReference; static final MethodHandle MH_selectAlternative; @@ -614,10 +615,12 @@ NF_guardWithCatch = new NamedFunction(MHI.getDeclaredMethod("guardWithCatch", MethodHandle.class, Class.class, MethodHandle.class, Object[].class)); NF_throwException = new NamedFunction(MHI.getDeclaredMethod("throwException", Throwable.class)); + NF_profileBoolean = new NamedFunction(MHI.getDeclaredMethod("profileBoolean", boolean.class, int[].class)); NF_checkSpreadArgument.resolve(); NF_guardWithCatch.resolve(); NF_throwException.resolve(); + NF_profileBoolean.resolve(); MH_castReference = IMPL_LOOKUP.findStatic(MHI, "castReference", MethodType.methodType(Object.class, Class.class, Object.class)); @@ -697,7 +700,26 @@ @LambdaForm.Hidden static MethodHandle selectAlternative(boolean testResult, MethodHandle target, MethodHandle fallback) { - return testResult ? target : fallback; + if (testResult) { + return target; + } else { + return fallback; + } + } + + // Intrinsified by C2. Counters are used during parsing to calculate branch frequencies. + @LambdaForm.Hidden + static + boolean profileBoolean(boolean result, int[] counters) { + // Profile is int[2] where [0] and [1] correspond to false and true occurrences respectively. + int idx = result ? 1 : 0; + try { + counters[idx] = Math.addExact(counters[idx], 1); + } catch (ArithmeticException e) { + // Avoid continuous overflow by halving the problematic count. + counters[idx] = counters[idx] / 2; + } + return result; } static @@ -708,13 +730,18 @@ assert(test.type().equals(type.changeReturnType(boolean.class)) && fallback.type().equals(type)); MethodType basicType = type.basicType(); LambdaForm form = makeGuardWithTestForm(basicType); - BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL(); BoundMethodHandle mh; - try { - mh = (BoundMethodHandle) - data.constructor().invokeBasic(type, form, - (Object) test, (Object) profile(target), (Object) profile(fallback)); + if (PROFILE_GWT) { + int[] counts = new int[2]; + mh = (BoundMethodHandle) + BoundMethodHandle.speciesData_LLLL().constructor().invokeBasic(type, form, + (Object) test, (Object) profile(target), (Object) profile(fallback), counts); + } else { + mh = (BoundMethodHandle) + BoundMethodHandle.speciesData_LLL().constructor().invokeBasic(type, form, + (Object) test, (Object) profile(target), (Object) profile(fallback)); + } } catch (Throwable ex) { throw uncaughtException(ex); } @@ -726,7 +753,7 @@ static MethodHandle profile(MethodHandle target) { if (DONT_INLINE_THRESHOLD >= 0) { - return makeBlockInlningWrapper(target); + return makeBlockInliningWrapper(target); } else { return target; } @@ -737,8 +764,13 @@ * Corresponding LambdaForm has @DontInline when compiled into bytecode. */ static - MethodHandle makeBlockInlningWrapper(MethodHandle target) { - LambdaForm lform = PRODUCE_BLOCK_INLINING_FORM.apply(target); + MethodHandle makeBlockInliningWrapper(MethodHandle target) { + LambdaForm lform; + if (DONT_INLINE_THRESHOLD > 0) { + lform = PRODUCE_BLOCK_INLINING_FORM.apply(target); + } else { + lform = PRODUCE_REINVOKER_FORM.apply(target); + } return new CountingWrapper(target, lform, PRODUCE_BLOCK_INLINING_FORM, PRODUCE_REINVOKER_FORM, DONT_INLINE_THRESHOLD); @@ -800,7 +832,7 @@ MethodHandle wrapper; if (isCounting) { LambdaForm lform; - lform = countingFormProducer.apply(target); + lform = countingFormProducer.apply(newTarget); wrapper = new CountingWrapper(newTarget, lform, countingFormProducer, nonCountingFormProducer, DONT_INLINE_THRESHOLD); } else { wrapper = newTarget; // no need for a counting wrapper anymore @@ -809,7 +841,8 @@ } boolean countDown() { - if (count <= 0) { + int c = count; + if (c <= 1) { // Try to limit number of updates. MethodHandle.updateForm() doesn't guarantee LF update visibility. if (isCounting) { isCounting = false; @@ -818,7 +851,7 @@ return false; } } else { - --count; + count = c - 1; return false; } } @@ -856,7 +889,10 @@ final int GET_TEST = nameCursor++; final int GET_TARGET = nameCursor++; final int GET_FALLBACK = nameCursor++; + final int GET_COUNTERS = PROFILE_GWT ? nameCursor++ : -1; final int CALL_TEST = nameCursor++; + final int PROFILE = (GET_COUNTERS != -1) ? nameCursor++ : -1; + final int TEST = nameCursor-1; // previous statement: either PROFILE or CALL_TEST final int SELECT_ALT = nameCursor++; final int CALL_TARGET = nameCursor++; assert(CALL_TARGET == SELECT_ALT+1); // must be true to trigger IBG.emitSelectAlternative @@ -864,12 +900,16 @@ MethodType lambdaType = basicType.invokerType(); Name[] names = arguments(nameCursor - ARG_LIMIT, lambdaType); - BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL(); + BoundMethodHandle.SpeciesData data = + (GET_COUNTERS != -1) ? BoundMethodHandle.speciesData_LLLL() + : BoundMethodHandle.speciesData_LLL(); names[THIS_MH] = names[THIS_MH].withConstraint(data); names[GET_TEST] = new Name(data.getterFunction(0), names[THIS_MH]); names[GET_TARGET] = new Name(data.getterFunction(1), names[THIS_MH]); names[GET_FALLBACK] = new Name(data.getterFunction(2), names[THIS_MH]); - + if (GET_COUNTERS != -1) { + names[GET_COUNTERS] = new Name(data.getterFunction(3), names[THIS_MH]); + } Object[] invokeArgs = Arrays.copyOfRange(names, 0, ARG_LIMIT, Object[].class); // call test @@ -877,15 +917,18 @@ invokeArgs[0] = names[GET_TEST]; names[CALL_TEST] = new Name(testType, invokeArgs); + // profile branch + if (PROFILE != -1) { + names[PROFILE] = new Name(Lazy.NF_profileBoolean, names[CALL_TEST], names[GET_COUNTERS]); + } // call selectAlternative - names[SELECT_ALT] = new Name(Lazy.MH_selectAlternative, names[CALL_TEST], - names[GET_TARGET], names[GET_FALLBACK]); + names[SELECT_ALT] = new Name(Lazy.MH_selectAlternative, names[TEST], names[GET_TARGET], names[GET_FALLBACK]); // call target or fallback invokeArgs[0] = names[SELECT_ALT]; names[CALL_TARGET] = new Name(basicType, invokeArgs); - lform = new LambdaForm("guard", lambdaType.parameterCount(), names); + lform = new LambdaForm("guard", lambdaType.parameterCount(), names, /*forceInline=*/true); return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWT, lform); } @@ -1629,4 +1672,13 @@ assert(elemType.isPrimitive()); return Lazy.MH_copyAsPrimitiveArray.bindTo(Wrapper.forPrimitiveType(elemType)); } + + /*non-public*/ static void assertSame(Object mh1, Object mh2) { + if (mh1 != mh2) { + String msg = String.format("mh1 != mh2: mh1 = %s (form: %s); mh2 = %s (form: %s)", + mh1, ((MethodHandle)mh1).form, + mh2, ((MethodHandle)mh2).form); + throw newInternalError(msg); + } + } } diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Mon Feb 16 08:47:40 2015 -0800 @@ -48,9 +48,11 @@ static final int COMPILE_THRESHOLD; static final int DONT_INLINE_THRESHOLD; static final int PROFILE_LEVEL; + static final boolean PROFILE_GWT; + static final int CUSTOMIZE_THRESHOLD; static { - final Object[] values = new Object[7]; + final Object[] values = new Object[9]; AccessController.doPrivileged(new PrivilegedAction() { public Void run() { values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES"); @@ -60,6 +62,8 @@ values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD", 0); values[5] = Integer.getInteger("java.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD", 30); values[6] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0); + values[7] = Boolean.parseBoolean(System.getProperty("java.lang.invoke.MethodHandle.PROFILE_GWT", "true")); + values[8] = Integer.getInteger("java.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD", 127); return null; } }); @@ -70,6 +74,12 @@ COMPILE_THRESHOLD = (Integer) values[4]; DONT_INLINE_THRESHOLD = (Integer) values[5]; PROFILE_LEVEL = (Integer) values[6]; + PROFILE_GWT = (Boolean) values[7]; + CUSTOMIZE_THRESHOLD = (Integer) values[8]; + + if (CUSTOMIZE_THRESHOLD < -1 || CUSTOMIZE_THRESHOLD > 127) { + throw newInternalError("CUSTOMIZE_THRESHOLD should be in [-1...127] range"); + } } /** Tell if any of the debugging switches are turned on. diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/security/AccessControlContext.java --- a/jdk/src/java.base/share/classes/java/security/AccessControlContext.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/security/AccessControlContext.java Mon Feb 16 08:47:40 2015 -0800 @@ -172,9 +172,24 @@ public AccessControlContext(AccessControlContext acc, DomainCombiner combiner) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(SecurityConstants.CREATE_ACC_PERMISSION); + this(acc, combiner, false); + } + + /** + * package private to allow calls from ProtectionDomain without performing + * the security check for {@linkplain SecurityConstants.CREATE_ACC_PERMISSION} + * permission + */ + AccessControlContext(AccessControlContext acc, + DomainCombiner combiner, + boolean preauthorized) { + if (!preauthorized) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(SecurityConstants.CREATE_ACC_PERMISSION); + this.isAuthorized = true; + } + } else { this.isAuthorized = true; } diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/java/security/ProtectionDomain.java --- a/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java Mon Feb 16 08:47:40 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -27,7 +27,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Map; @@ -60,35 +59,44 @@ */ public class ProtectionDomain { + private static class JavaSecurityAccessImpl implements JavaSecurityAccess { + + private JavaSecurityAccessImpl() { + } + + @Override + public T doIntersectionPrivilege( + PrivilegedAction action, + final AccessControlContext stack, + final AccessControlContext context) { + if (action == null) { + throw new NullPointerException(); + } + + return AccessController.doPrivileged( + action, + getCombinedACC(context, stack) + ); + } + + @Override + public T doIntersectionPrivilege( + PrivilegedAction action, + AccessControlContext context) { + return doIntersectionPrivilege(action, + AccessController.getContext(), context); + } + + private static AccessControlContext getCombinedACC(AccessControlContext context, AccessControlContext stack) { + AccessControlContext acc = new AccessControlContext(context, stack.getCombiner(), true); + + return new AccessControlContext(stack.getContext(), acc).optimize(); + } + } static { // Set up JavaSecurityAccess in SharedSecrets - SharedSecrets.setJavaSecurityAccess( - new JavaSecurityAccess() { - public T doIntersectionPrivilege( - PrivilegedAction action, - final AccessControlContext stack, - final AccessControlContext context) - { - if (action == null) { - throw new NullPointerException(); - } - return AccessController.doPrivileged( - action, - new AccessControlContext( - stack.getContext(), context).optimize() - ); - } - - public T doIntersectionPrivilege( - PrivilegedAction action, - AccessControlContext context) - { - return doIntersectionPrivilege(action, - AccessController.getContext(), context); - } - } - ); + SharedSecrets.setJavaSecurityAccess(new JavaSecurityAccessImpl()); } /* CodeSource */ diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/java.base/share/classes/sun/misc/Unsafe.java --- a/jdk/src/java.base/share/classes/sun/misc/Unsafe.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/src/java.base/share/classes/sun/misc/Unsafe.java Mon Feb 16 08:47:40 2015 -0800 @@ -25,8 +25,8 @@ package sun.misc; -import java.security.*; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.security.ProtectionDomain; import sun.reflect.CallerSensitive; import sun.reflect.Reflection; @@ -189,205 +189,39 @@ * If the reference o is non-null, car marks or * other store barriers for that object (if the VM requires them) * are updated. - * @see #putInt(Object, int, int) + * @see #putInt(Object, long, int) */ public native void putObject(Object o, long offset, Object x); /** @see #getInt(Object, long) */ public native boolean getBoolean(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putBoolean(Object o, long offset, boolean x); /** @see #getInt(Object, long) */ public native byte getByte(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putByte(Object o, long offset, byte x); /** @see #getInt(Object, long) */ public native short getShort(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putShort(Object o, long offset, short x); /** @see #getInt(Object, long) */ public native char getChar(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putChar(Object o, long offset, char x); /** @see #getInt(Object, long) */ public native long getLong(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putLong(Object o, long offset, long x); /** @see #getInt(Object, long) */ public native float getFloat(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putFloat(Object o, long offset, float x); /** @see #getInt(Object, long) */ public native double getDouble(Object o, long offset); - /** @see #putInt(Object, int, int) */ + /** @see #putInt(Object, long, int) */ public native void putDouble(Object o, long offset, double x); - /** - * This method, like all others with 32-bit offsets, was native - * in a previous release but is now a wrapper which simply casts - * the offset to a long value. It provides backward compatibility - * with bytecodes compiled against 1.4. - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public int getInt(Object o, int offset) { - return getInt(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putInt(Object o, int offset, int x) { - putInt(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public Object getObject(Object o, int offset) { - return getObject(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putObject(Object o, int offset, Object x) { - putObject(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public boolean getBoolean(Object o, int offset) { - return getBoolean(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putBoolean(Object o, int offset, boolean x) { - putBoolean(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public byte getByte(Object o, int offset) { - return getByte(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putByte(Object o, int offset, byte x) { - putByte(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public short getShort(Object o, int offset) { - return getShort(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putShort(Object o, int offset, short x) { - putShort(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public char getChar(Object o, int offset) { - return getChar(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putChar(Object o, int offset, char x) { - putChar(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public long getLong(Object o, int offset) { - return getLong(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putLong(Object o, int offset, long x) { - putLong(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public float getFloat(Object o, int offset) { - return getFloat(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putFloat(Object o, int offset, float x) { - putFloat(o, (long)offset, x); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public double getDouble(Object o, int offset) { - return getDouble(o, (long)offset); - } - - /** - * @deprecated As of 1.4.1, cast the 32-bit offset argument to a long. - * See {@link #staticFieldOffset}. - */ - @Deprecated - public void putDouble(Object o, int offset, double x) { - putDouble(o, (long)offset, x); - } - // These work on values in the C heap. /** @@ -579,58 +413,6 @@ public static final int INVALID_FIELD_OFFSET = -1; /** - * Returns the offset of a field, truncated to 32 bits. - * This method is implemented as follows: - *
-     * public int fieldOffset(Field f) {
-     *     if (Modifier.isStatic(f.getModifiers()))
-     *         return (int) staticFieldOffset(f);
-     *     else
-     *         return (int) objectFieldOffset(f);
-     * }
-     * 
- * @deprecated As of 1.4.1, use {@link #staticFieldOffset} for static - * fields and {@link #objectFieldOffset} for non-static fields. - */ - @Deprecated - public int fieldOffset(Field f) { - if (Modifier.isStatic(f.getModifiers())) - return (int) staticFieldOffset(f); - else - return (int) objectFieldOffset(f); - } - - /** - * Returns the base address for accessing some static field - * in the given class. This method is implemented as follows: - *
-     * public Object staticFieldBase(Class c) {
-     *     Field[] fields = c.getDeclaredFields();
-     *     for (int i = 0; i < fields.length; i++) {
-     *         if (Modifier.isStatic(fields[i].getModifiers())) {
-     *             return staticFieldBase(fields[i]);
-     *         }
-     *     }
-     *     return null;
-     * }
-     * 
- * @deprecated As of 1.4.1, use {@link #staticFieldBase(Field)} - * to obtain the base pertaining to a specific {@link Field}. - * This method works only for JVMs which store all statics - * for a given class in one place. - */ - @Deprecated - public Object staticFieldBase(Class c) { - Field[] fields = c.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - if (Modifier.isStatic(fields[i].getModifiers())) { - return staticFieldBase(fields[i]); - } - } - return null; - } - - /** * Report the location of a given field in the storage allocation of its * class. Do not expect to perform any sort of arithmetic on this offset; * it is just a cookie which is passed to the unsafe heap memory accessors. @@ -648,7 +430,7 @@ * must preserve all bits of static field offsets. * @see #getInt(Object, long) */ - public native long staticFieldOffset(Field f); + public native long objectFieldOffset(Field f); /** * Report the location of a given static field, in conjunction with {@link @@ -667,7 +449,7 @@ * this method reports its result as a long value. * @see #getInt(Object, long) */ - public native long objectFieldOffset(Field f); + public native long staticFieldOffset(Field f); /** * Report the location of a given static field, in conjunction with {@link @@ -748,7 +530,7 @@ * Report the scale factor for addressing elements in the storage * allocation of a given array class. However, arrays of "narrow" types * will generally not work properly with accessors like {@link - * #getByte(Object, int)}, so the scale factor for such classes is reported + * #getByte(Object, long)}, so the scale factor for such classes is reported * as zero. * * @see #arrayBaseOffset @@ -1136,11 +918,11 @@ public native void fullFence(); /** - * Throws IllegalAccessError; for use by the VM. + * Throws IllegalAccessError; for use by the VM for access control + * error support. * @since 1.8 */ private static void throwIllegalAccessError() { - throw new IllegalAccessError(); + throw new IllegalAccessError(); } - } diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/Probe.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/Probe.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing; - -/** - * The {@code Probe} interface represents a tracepoint. - * - * A {@code Probe} instance is obtained by calling the - * {@code Provider.getProbe()} method of a provider instance created by - * {@code ProviderFactory.createProvider()}. A {@code Probe} can be used to - * trigger a probe manually (provided the correct arguments are passed to - * it), or to check a probe to see if anything is currently tracing it. - *

- * A tracing check can be used to avoid lengthy work that might be - * needed to set up the probe's arguments. However, checking - * whether the probe is enabled generally takes the same amount of time - * as actually triggering the probe. So, you should only check a probe's status - * without triggering it if setting up the arguments is very expensive. - *

- * Users do not need to implement this interface: instances are - * created automatically by the system when a {@code Provider)} instance is - * created. - *

- * @since 1.7 - */ - -public interface Probe { - /** - * Checks whether there is an active trace of this probe. - * - * @return true if an active trace is detected. - */ - boolean isEnabled(); - - /** - * Determines whether a tracepoint is enabled. - * - * Typically, users do not need to use this method. It is called - * automatically when a Provider's instance method is called. Calls to - * this method expect the arguments to match the declared parameters for - * the method associated with the probe. - * - * @param args the parameters to pass to the method. - * @throws IllegalArgumentException if the provided parameters do not - * match the method declaration for this probe. - */ - void trigger(Object ... args); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/ProbeName.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/ProbeName.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * An annotation used to override the name of a probe. - *

- * This annotation can be added to a method in a user-defined {@code Provider} - * interface, to set the name that will be used for the generated probe - * associated with that method. Without this annotation, the name will be the - * name of the method. - *

- * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ProbeName { - String value(); -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/Provider.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/Provider.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing; - -/** - * {@code Provider} is a superinterface for user-defined tracing providers. - *

- * To define tracepoints, users must extend this interface - * and then use a {@code ProviderFactory} to create an instance of the - * newly-defined interface. Each method in the defined interface represents a - * tracepoint (or probe), which can be triggered by calling the associated - * method on the returned instance. - *

- * This interface also contains a {@code getProbe()} method, which can be - * used to get direct handles to the {@code Probe} objects themselves. - * {@code Probe} objects can be triggered manually, or they can be queried to - * check their state. - *

- * When an application has finished triggering probes, it should call - * {@code dispose()} to free up any system resources associated with the - * Provider. - *

- * All methods declared in a subclass of this interface should have a - * {@code void} return type. Methods can have parameters, and when called the - * values of the arguments will be passed to the tracing implementation. - * If any methods do not have a {@code void} return type, an - * {@code java.lang.IllegalArgumentException} will be thrown when the - * provider is registered. - * @since 1.7 - */ - -public interface Provider { - /** - * Retrieves a reference to a Probe object, which is used to check status - * or to trigger the probe manually. - * - * If the provided method parameter is not a method of the provider - * interface, or if the provider interface has been disposed, then - * this returns null - * - * @param method a method declared in the provider. - * @return the specified probe represented by that method, or null. - */ - Probe getProbe(java.lang.reflect.Method method); - - /** - * Disposes system resources associated with this provider. - * - * After calling this method, triggering the probes will have no effect. - * Additional calls to this method after the first call are ignored. - */ - void dispose(); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/ProviderFactory.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/ProviderFactory.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ - -package com.sun.tracing; - -import java.util.HashSet; -import java.io.PrintStream; -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -import sun.tracing.NullProviderFactory; -import sun.tracing.PrintStreamProviderFactory; -import sun.tracing.MultiplexProviderFactory; -import sun.tracing.dtrace.DTraceProviderFactory; - -/** - * {@code ProviderFactory} is a factory class used to create instances of - * providers. - * - * To enable tracing in an application, this class must be used to create - * instances of the provider interfaces defined by users. - * The system-defined factory is obtained by using the - * {@code getDefaultFactory()} static method. The resulting instance can be - * used to create any number of providers. - * - * @since 1.7 - */ -public abstract class ProviderFactory { - - protected ProviderFactory() {} - - /** - * Creates an implementation of a Provider interface. - * - * @param cls the provider interface to be defined. - * @return an implementation of {@code cls}, whose methods, when called, - * will trigger tracepoints in the application. - * @throws NullPointerException if cls is null - * @throws IllegalArgumentException if the class definition contains - * non-void methods - */ - public abstract T createProvider(Class cls); - - /** - * Returns an implementation of a {@code ProviderFactory} which - * creates instances of Providers. - * - * The created Provider instances will be linked to all appropriate - * and enabled system-defined tracing mechanisms in the JDK. - * - * @return a {@code ProviderFactory} that is used to create Providers. - */ - public static ProviderFactory getDefaultFactory() { - HashSet factories = new HashSet(); - - // Try to instantiate a DTraceProviderFactory - String prop = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty("com.sun.tracing.dtrace")); - - if ( (prop == null || !prop.equals("disable")) && - DTraceProviderFactory.isSupported() ) { - factories.add(new DTraceProviderFactory()); - } - - // Try to instantiate an output stream factory - prop = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty("sun.tracing.stream")); - if (prop != null) { - for (String spec : prop.split(",")) { - PrintStream ps = getPrintStreamFromSpec(spec); - if (ps != null) { - factories.add(new PrintStreamProviderFactory(ps)); - } - } - } - - // See how many factories we instantiated, and return an appropriate - // factory that encapsulates that. - if (factories.size() == 0) { - return new NullProviderFactory(); - } else if (factories.size() == 1) { - return factories.toArray(new ProviderFactory[1])[0]; - } else { - return new MultiplexProviderFactory(factories); - } - } - - private static PrintStream getPrintStreamFromSpec(final String spec) { - try { - // spec is in the form of ., where is - // a fully specified class name, and is a static member - // in that class. The must be a 'PrintStream' or subtype - // in order to be used. - final int fieldpos = spec.lastIndexOf('.'); - final Class cls = Class.forName(spec.substring(0, fieldpos)); - - Field f = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Field run() throws NoSuchFieldException { - return cls.getField(spec.substring(fieldpos + 1)); - } - }); - - return (PrintStream)f.get(null); - } catch (ClassNotFoundException e) { - throw new AssertionError(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (PrivilegedActionException e) { - throw new AssertionError(e); - } - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/ProviderName.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/ProviderName.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * An annotation used to specify the name of a provider. - *

- * This annotation can be added to a user-defined {@code Provider} - * interface, to set the name that will be used - * for the provider in the generated probes. Without this annotation, - * the simple class name of the provider interface is used. - *

- * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface ProviderName { - String value(); -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ArgsAttributes.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ArgsAttributes.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - - -/** - * This annotation describes the interface attributes of the probe arguments in - * a single provider. - * - * This annotation can be added to a user-defined {@code Provider} specification - * interface to set the stability attributes of the probe arguments, for - * all the probes specified in that provider. - *

- * If this annotation is not present, the interface attributes for the - * arguments are Private/Private/Unknown. - *

- * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE }) -public @interface ArgsAttributes { - Attributes value(); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/Attributes.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/Attributes.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - - -/** - * This annotation describes the interface's field attributes - * for the probes in a provider. - * - * This annotation provides the contents of field-specific annotations - * that specify the stability attributes and dependency class of a - * particular field, for the probes in a provider. - *

- * The default interface attributes for unspecified fields is - * Private/Private/Unknown. - *

- * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target({}) -public @interface Attributes { - /** - * The stability level of the name. - */ - StabilityLevel name() default StabilityLevel.PRIVATE; - - /** - * The stability level of the data. - */ - StabilityLevel data() default StabilityLevel.PRIVATE; - - /** - * The interface attribute's dependency class. - */ - DependencyClass dependency() default DependencyClass.UNKNOWN; -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/DependencyClass.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/DependencyClass.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -/** - * Enumeration for the DTrace dependency classes. - * - * @see Solaris Dynamic Tracing Guide for details, Chapter 39: Stability - * @since 1.7 - */ -public enum DependencyClass { - /** - * The interface has an unknown set of architectural dependencies. - */ - UNKNOWN (0), - /** - * The interface is specific to the CPU model of the current system. - */ - CPU (1), - /** - * The interface is specific to the hardware platform of the current - * system. - */ - PLATFORM (2), - /** - * The interface is specific to the hardware platform group of the - * current system. - */ - GROUP (3), - /** - * The interface is specific to the instruction set architecture (ISA) - * supported by the microprocessors on this system. - */ - ISA (4), - /** - * The interface is common to all Solaris systems regardless of the - * underlying hardware. - */ - COMMON (5); - - public String toDisplayString() { - return toString().substring(0,1) + - toString().substring(1).toLowerCase(); - } - - public int getEncoding() { return encoding; } - - private int encoding; - - private DependencyClass(int encoding) { - this.encoding = encoding; - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/FunctionAttributes.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/FunctionAttributes.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * This annotation describes the interface attributes of the - * {@code function} field for a single provider. - * - * This annotation can be added to a user-defined {@code Provider} specification - * interface to set the stability attributes of the {@code function} field for - * all probes specified in that provider. - *

- * If this annotation is not present, the interface attributes for the - * {@code function} field are Private/Private/Unknown. - *

- * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE }) -public @interface FunctionAttributes { - Attributes value(); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/FunctionName.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/FunctionName.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * An annotation used to specify the {@code function} field for a DTrace probe. - * - * This annotation can be added to a method in a user-defined Provider - * specification interface to set the {@code function} field that is used - * for the generated DTrace probe associated with that method. - *

- * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface FunctionName { - String value(); -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ModuleAttributes.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ModuleAttributes.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * This annotation is used to describe the interface attributes of the - * {@code module} field for a single provider. - * - * This annotation can be added to a user-defined Provider specification - * interface to set the stability attributes of the {@code module} field for - * all probes specified in that provider. - *

- * If this annotation is not present, the interface attributes for the - * {@code module} field is Private/Private/Unknown. - *

- * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE }) -public @interface ModuleAttributes { - Attributes value(); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ModuleName.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ModuleName.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * An annotation used to specify the {@code module} field for a DTrace probe. - * - * This annotation can be added to a method in a user-defined Provider - * specification interface to set the {@code module} field that will be used - * for the generated DTrace probe associated with that method. - *

- * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface ModuleName { - String value(); -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/NameAttributes.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/NameAttributes.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * This annotation describes the interface attributes of the - * {@code name} field for a single provider. - * - * This annotation can be added to a user-defined Provider specification - * interface to set the stability attributes of the {@code name} field for - * all probes specified in that provider. - *

- * If this annotation is not present, the interface attributes for the - * {@code name} field will be Private/Private/Unknown. - *

- * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE }) -public @interface NameAttributes { - Attributes value(); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ProviderAttributes.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/ProviderAttributes.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.ElementType; - -/** - * This annotation is used to describe the interface attributes of the - * {@code provider} field for a single provider. - * - * This annotation can be added to a user-defined Provider specification - * interface to set the stability attributes of the {@code provider} field for - * all probes specified in that provider. - *

- * If this annotation is not present, the interface attributes for the - * {@code provider} field will be Private/Private/Unknown. - *

- * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE }) -public @interface ProviderAttributes { - Attributes value(); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/StabilityLevel.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/StabilityLevel.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2008, 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 com.sun.tracing.dtrace; - -/** - * Enumeration for the DTrace stability levels. - * - * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - * @since 1.7 - */ -public enum StabilityLevel { - /** - * The interface is private to DTrace and represents an implementation - * detail of DTrace. - */ - INTERNAL (0), - /** - * The interface is private to Sun for use by other Sun products. It is - * not yet publicly documented for use by customers and ISVs. - */ - PRIVATE (1), - /** - * The interface is supported in the current release but is scheduled - * to be removed, most likely in a future minor release. - */ - OBSOLETE (2), - /** - * The interface is controlled by an entity other than Sun. - */ - EXTERNAL (3), - /** - * The interface gives developers early access to new or - * rapidly changing technology or to an implementation artifact that is - * essential for observing or debugging system behavior. A more - * stable solution is anticipated in the future. - */ - UNSTABLE (4), - /** - * The interface might eventually become Standard or Stable but is - * still in transition. - */ - EVOLVING (5), - /** - * The interface is a mature interface under Sun's control. - */ - STABLE (6), - /** - * The interface complies with an industry standard. - */ - STANDARD (7); - - String toDisplayString() { - return toString().substring(0,1) + - toString().substring(1).toLowerCase(); - } - - public int getEncoding() { return encoding; } - - private int encoding; - - private StabilityLevel(int encoding) { - this.encoding = encoding; - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/package-info.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/dtrace/package-info.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2008, 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. - */ - -/** - * This package contains annotations and enumerations that are used to - * add DTrace-specific information to a tracing provider. - *

- * The DTrace-specific annotations modify the attributes of a DTrace provider - * implementation when it is used by the tracing subsystem. The annotations are - * added to a {@code com.sun.tracing} provider specification to control - * specific attributes of the provider as it relates to DTrace. - *

- * Any other tracing subsystems supported by the system will ignore these - * annotations. - *

- * DTrace probes have additional fields and stability attributes that are - * not accounted for in the generic tracing package. If unspecified, the - * default values are used for the stability and dependency attributes of - * probes, as well as for the module and field names of the generated probes. - * The values can be specified by adding the appropriate annotations to the - * provider specification. - *

- * The {@code FunctionName} annotation is used to annotate the tracepoint - * methods defined in the provider specification. The value of this annotation - * is used as the {@code function} field in the generated DTrace probes. It - * is typically set to the name of the enclosing function where the - * tracepoint is triggered. - *

- * The {@code ModuleName} annotation is used to annotate the provider - * specification itself and applies to all the probes in the provider. It - * sets the value of the {@code module} field in the generated DTrace probes. - *

- * The remaining annotations, are also applied to the provider itself, and - * are used to set the stability and dependency attributes of all probes in - * that provider. Each probe field and the probe arguments can be - * independently assigned interface attributes to control the stability - * ratings of the probes. - *

- * Here is an example of how to declare a provider, specifying additional DTrace - * data: -

-    @ProviderName("my_app_provider")
-    @ModuleName("app.jar")
-    @ProviderAttributes(@Attributes={
-        name=StabilityLevel.STABLE,data=StabilityLevel.STABLE,
-        dependency=DependencyClass.COMMON})
-    @ProbeAttributes(@Attributes={
-        name=StabilityLevel.STABLE,data=StabilityLevel.STABLE,
-        dependency=DependencyClass.COMMON})
-    @ModuleAttributes(@Attributes={name=StabilityLevel.UNSTABLE})
-    public class MyProvider {
-        @FunctionName("main") void startProbe();
-    }
-
- *

- * @see Solaris Dynamic Tracing Guide, Chapter 34: Statically Defined Tracing for User Applications - * @see Solaris Dynamic Tracing Guide, Chapter 39: Stability - */ - -package com.sun.tracing.dtrace; diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/com/sun/tracing/package-info.java --- a/jdk/src/jdk.runtime/share/classes/com/sun/tracing/package-info.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2008, 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. - */ - -/** - * This package provides a mechanism for defining and - * inserting tracepoints into Java-technology based applications, which - * can then be monitored by the tracing tools available on the system. - *

- * To add tracepoints to a program, you must first decide where to place the - * tracepoints, what the logical names are for these points, what information - * will be available to the tracing mechanisms at each point, and decide upon - * any logical grouping. - *

- * You add instrumentation to a program in three steps: - *

    - *
  • First, declare tracepoints by creating interfaces to define - * them, and include these interfaces in the program definition. - * The declared interfaces are standard Java technology-based - * interfaces and are compiled with the program.
  • - *
  • Second, add code in the application to create an instance of the - * interface at some point during the initialization of the application, - * using a factory class provided by the system. The reference to the - * instance can be stored as a global static, or passed as context to all - * the places where it is needed.
  • - *
  • Finally, add the actual tracepoints to the desired locations in the - * application by inserting a call to one of the methods defined in the - * interface, via the factory-created reference.
  • - *
- *

- * The method calls representing the tracepoints have no logical - * impact on the program. The side effect of the call is that any - * activated tracing mechanisms will be notified that the tracepoint has - * been hit, and will take whatever actions are appropriate (for example, - * logging the tracepoint, or triggering a DTrace probe, etc.). In most - * cases, the impact on performance of adding tracepoints to the application - * will be minimal. - *

- * Each logical grouping of tracepoints should be defined in a common - * interface, called a provider. An application can have one or many - * providers. Each provider is independent and can be created whenever - * it is appropriate for that provider, for example, when a subsytem is - * initialized. Providers should be disposed of when they are no longer - * needed, to free up any associated system resources. Each tracepoint - * in a provider is represented by a method in that interface. These methods - * are referred to as probes. The method signature determines the probe - * parameters. A call to the method with the specified parameters triggers - * the probe and makes its parameter values visible to any associated tracing - * mechanism. - *

- * User-defined interfaces which represent providers must extend the - * {@code Provider} interface. To activate the system-defined - * tracing mechanisms, you must obtain an instance of the - * {@code ProviderFactory} class, and pass the class of the provider to - * the {@code createProvider()} method. The returned instance is then used to - * trigger the probes later in the application. - *

- * In addition to triggering the probes, the provider instance can be used - * to obtain direct references to the {@code Probe} objects, which can be used - * directly for triggering, or can be queried to determine whether the probe is - * currently being traced. The {@code Provider} interface also defines a - * {@code Provider.dispose()} method which is used to free up any resources - * that might be associated with that provider. - *

- * When a probe is triggered, any activated tracing system will be given - * the provider name, the probe name, and the values of the probe arguments. - * The tracing system is free to consume this data is whatever way is - * appropriate. - * By default, the provider name is the same as the class name of the interface - * that defines the provider. Similarly, the probe name is - * the name of the method that defines the probe. These default values - * can be over-ridden by annotations. The provider definition can be - * annotated with the {@code @ProviderName} annotation, whose value will - * indicate the provider name that the tracing system will use. Similarly, - * the {@code @ProbeName} annotation annotates a declared method and - * indicates the probe name that should be used in the place of the - * method name. These annotations can be used to define providers and - * probes with the same name, in cases where the semantics of the Java language - * may prevent this. - *

- * Here is a very small and simple usage example: - *

- * -

-   import com.sun.tracing.Provider;
-   import com.sun.tracing.ProviderFactory;
-
-   interface MyProvider extends Provider {
-       void startProbe();
-       void finishProbe(int value);
-   }
-
-   public class MyApplication {
-       public static void main(String argv[]) {
-           ProviderFactory factory = ProviderFactory.getDefaultFactory();
-           MyProvider trace = factory.createProvider(MyProvider.class);
-
-           trace.startProbe();
-           int result = foo();
-           trace.finishProbe(result);
-
-           trace.dispose();
-       }
-   }
-
- *

- * The Java Development Kit (JDK) currently only includes one system-defined - * tracing framework: DTrace. DTrace is enabled automatically whenever an - * application is run on a system and a JDK release that supports it. When - * DTrace is enabled, probes are made available for listing and matching by - * DTrace scripts as soon as the provider is created. At the tracepoint, an - * associated DTrace script is informed of the creation of the provider, and - * it takes whatever action it is designed to take. Tracepoints in the - * program have the following DTrace probe names:
- * {@code :::} - * Where: - *

    - *
  • {@code } the provider name as specified by the application
  • - *
  • {@code } the operating system process ID
  • - *
  • {@code } undefined, unless specified by the application
  • - *
  • {@code } undefined, unless specified by the application
  • - *
  • {@code } the probe name as specified by the application
  • - *
- *

- * The {@code com.sun.tracing.dtrace} package contains additional - * annotations that can be used to control the names used for the - * module and function fields, as well as annotations - * that can be added to the provider to control probe stability and dependency - * attributes. - *

- * Integer, float and string probe parameters are made available to DTrace - * using - * the built-in argument variables, {@code arg0 ... arg_n}. Integer-types - * are passed by value (boxed values are unboxed), floating-point types are - * passed as encoded integer - * arguments, and {@code java.lang.String} objects are converted - * to UTF8 strings, so they can be read into the DTrace script using the - * {@code copyinstr()} intrinsic. Non-string and non-boxed primitive - * reference arguments are only - * placeholders and have no value. - *

- * Using the example above, with a theoretical process ID of 123, these are - * the probes that can be traced from DTrace: -

-    MyProvider123:::startProbe
-    MyProvider123:::finishProbe
-
- * When {@code finishProbe} executes, {@code arg0} will contain the - * value of {@code result}. - *

- * The DTrace tracing mechanism is enabled for all providers, apart from in the - * following circumstances: - *

    - *
  • DTrace is not supported on the underlying system.
  • - *
  • The property {@code com.sun.tracing.dtrace} is set to "disable".
  • - *
  • The RuntimePermission {@code com.sun.tracing.dtrace.createProvider} - * is denied to the process.
  • - *
- *

- */ - -package com.sun.tracing; diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/MultiplexProviderFactory.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/MultiplexProviderFactory.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing; - -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import com.sun.tracing.ProviderFactory; -import com.sun.tracing.Provider; -import com.sun.tracing.Probe; - -/** - * Factory class to create tracing Providers. - * - * This factory creates a "multiplex provider", which is a provider that - * encapsulates a list of providers and whose probes trigger a corresponding - * trigger in each of the encapsulated providers' probes. - * - * This is used when there are multiple tracing frameworks activated at once. - * A user-defined provider gets implementation for each of the activated - * frameworks and this multiplex framework is what is ultimately passed - * back to the user. All probe triggers are multiplexed to each - * active framework. - * - * @since 1.7 - */ -public class MultiplexProviderFactory extends ProviderFactory { - - private Set factories; - - public MultiplexProviderFactory(Set factories) { - this.factories = factories; - } - - public T createProvider(Class cls) { - HashSet providers = new HashSet(); - for (ProviderFactory factory : factories) { - providers.add(factory.createProvider(cls)); - } - MultiplexProvider provider = new MultiplexProvider(cls, providers); - provider.init(); - return provider.newProxyInstance(); - } -} - -class MultiplexProvider extends ProviderSkeleton { - - private Set providers; - - protected ProbeSkeleton createProbe(Method m) { - return new MultiplexProbe(m, providers); - } - - MultiplexProvider(Class type, Set providers) { - super(type); - this.providers = providers; - } - - public void dispose() { - for (Provider p : providers) { - p.dispose(); - } - super.dispose(); - } -} - -class MultiplexProbe extends ProbeSkeleton { - - private Set probes; - - MultiplexProbe(Method m, Set providers) { - super(m.getParameterTypes()); - probes = new HashSet(); - for (Provider p : providers) { - Probe probe = p.getProbe(m); - if (probe != null) { - probes.add(probe); - } - } - } - - public boolean isEnabled() { - for (Probe p : probes) { - if (p.isEnabled()) { - return true; - } - } - return false; - } - - public void uncheckedTrigger(Object[] args) { - for (Probe p : probes) { - try { - // try the fast path - ProbeSkeleton ps = (ProbeSkeleton)p; - ps.uncheckedTrigger(args); - } catch (ClassCastException e) { - // Probe.trigger takes an "Object ..." varargs parameter, - // so we can't call it directly. - try { - Method m = Probe.class.getMethod( - "trigger", Class.forName("[java.lang.Object")); - m.invoke(p, args); - } catch (Exception e1) { - assert false; // This shouldn't happen - } - } - } - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/NullProviderFactory.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/NullProviderFactory.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing; - -import java.lang.reflect.Method; - -import com.sun.tracing.ProviderFactory; -import com.sun.tracing.Provider; - -/** - * Factory class to create tracing Providers. - * - * This factory will create tracing instances that do nothing. - * It is used when no tracing is desired, but Provider instances still - * must be generated so that tracing calls in the application continue to - * run. - * - * @since 1.7 - */ -public class NullProviderFactory extends ProviderFactory { - - /** - * Creates and returns a Null provider. - * - * See comments at {@code ProviderSkeleton.createProvider()} for more - * details. - * - * @return a provider whose probe trigger are no-ops. - */ - public T createProvider(Class cls) { - NullProvider provider = new NullProvider(cls); - provider.init(); - return provider.newProxyInstance(); - } -} - -class NullProvider extends ProviderSkeleton { - - NullProvider(Class type) { - super(type); - } - - protected ProbeSkeleton createProbe(Method m) { - return new NullProbe(m.getParameterTypes()); - } -} - -class NullProbe extends ProbeSkeleton { - - public NullProbe(Class[] parameters) { - super(parameters); - } - - public boolean isEnabled() { - return false; - } - - public void uncheckedTrigger(Object[] args) { - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/PrintStreamProviderFactory.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/PrintStreamProviderFactory.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing; - -import java.lang.reflect.Method; -import java.io.PrintStream; -import java.util.HashMap; - -import com.sun.tracing.ProviderFactory; -import com.sun.tracing.Provider; -import com.sun.tracing.ProviderName; -import com.sun.tracing.Probe; -import com.sun.tracing.ProbeName; - -/** - * Factory class to create tracing Providers. - * - * This factory will create tracing instances that print to a PrintStream - * when activated. - * - * @since 1.7 - */ -public class PrintStreamProviderFactory extends ProviderFactory { - - private PrintStream stream; - - public PrintStreamProviderFactory(PrintStream stream) { - this.stream = stream; - } - - public T createProvider(Class cls) { - PrintStreamProvider provider = new PrintStreamProvider(cls, stream); - provider.init(); - return provider.newProxyInstance(); - } -} - -class PrintStreamProvider extends ProviderSkeleton { - - private PrintStream stream; - private String providerName; - - protected ProbeSkeleton createProbe(Method m) { - String probeName = getAnnotationString(m, ProbeName.class, m.getName()); - return new PrintStreamProbe(this, probeName, m.getParameterTypes()); - } - - PrintStreamProvider(Class type, PrintStream stream) { - super(type); - this.stream = stream; - this.providerName = getProviderName(); - } - - PrintStream getStream() { - return stream; - } - - String getName() { - return providerName; - } -} - -class PrintStreamProbe extends ProbeSkeleton { - - private PrintStreamProvider provider; - private String name; - - PrintStreamProbe(PrintStreamProvider p, String name, Class[] params) { - super(params); - this.provider = p; - this.name = name; - } - - public boolean isEnabled() { - return true; - } - - public void uncheckedTrigger(Object[] args) { - StringBuilder sb = new StringBuilder(); - sb.append(provider.getName()); - sb.append("."); - sb.append(name); - sb.append("("); - boolean first = true; - for (Object o : args) { - if (first == false) { - sb.append(","); - } else { - first = false; - } - sb.append(o.toString()); - } - sb.append(")"); - provider.getStream().println(sb.toString()); - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/ProbeSkeleton.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/ProbeSkeleton.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing; - -import java.lang.reflect.Method; -import java.lang.reflect.Field; -import com.sun.tracing.Probe; - -/** - * Provides common code for implementation of {@code Probe} classes. - * - * @since 1.7 - */ -public abstract class ProbeSkeleton implements Probe { - - protected Class[] parameters; - - protected ProbeSkeleton(Class[] parameters) { - this.parameters = parameters; - } - - public abstract boolean isEnabled(); // framework-dependent - - /** - * Triggers the probe with verified arguments. - * - * The caller of this method must have already determined that the - * arity and types of the arguments match what the probe was - * declared with. - */ - public abstract void uncheckedTrigger(Object[] args); // framework-dependent - - private static boolean isAssignable(Object o, Class formal) { - if (o != null) { - if ( !formal.isInstance(o) ) { - if ( formal.isPrimitive() ) { // o might be a boxed primitive - try { - // Yuck. There must be a better way of doing this - Field f = o.getClass().getField("TYPE"); - return formal.isAssignableFrom((Class)f.get(null)); - } catch (Exception e) { - /* fall-through. */ - } - } - return false; - } - } - return true; - } - - /** - * Performs a type-check of the parameters before triggering the probe. - */ - public void trigger(Object ... args) { - if (args.length != parameters.length) { - throw new IllegalArgumentException("Wrong number of arguments"); - } else { - for (int i = 0; i < parameters.length; ++i) { - if ( !isAssignable(args[i], parameters[i]) ) { - throw new IllegalArgumentException( - "Wrong type of argument at position " + i); - } - } - uncheckedTrigger(args); - } - } -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/ProviderSkeleton.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/ProviderSkeleton.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.AnnotatedElement; -import java.lang.annotation.Annotation; -import java.util.HashMap; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import com.sun.tracing.Provider; -import com.sun.tracing.Probe; -import com.sun.tracing.ProviderName; - -/** - * Provides a common code for implementation of {@code Provider} classes. - * - * Each tracing subsystem needs to provide three classes, a factory - * (derived from {@code ProviderFactory}, a provider (a subclass of - * {@code Provider}, and a probe type (subclass of {@code ProbeSkeleton}). - * - * The factory object takes a user-defined interface and provides an - * implementation of it whose method calls will trigger probes in the - * tracing framework. - * - * The framework's provider class, and its instances, are not seen by the - * user at all -- they usually sit in the background and receive and dispatch - * the calls to the user's provider interface. The {@code ProviderSkeleton} - * class provides almost all of the implementation needed by a framework - * provider. Framework providers must only provide a constructor and - * disposal method, and implement the {@code createProbe} method to create - * an appropriate {@code ProbeSkeleton} subclass. - * - * The framework's probe class provides the implementation of the two - * probe methods, {@code isEnabled()} and {@code uncheckedTrigger()}. Both are - * framework-dependent implementations. - * - * @since 1.7 - */ - -public abstract class ProviderSkeleton implements InvocationHandler, Provider { - - protected boolean active; // set to false after dispose() is called - protected Class providerType; // user's interface - protected HashMap probes; // methods to probes - - - /** - * Creates a framework-specific probe subtype. - * - * This method is implemented by the framework's provider and returns - * framework-specific probes for a method. - * - * @param method A method in the user's interface - * @return a subclass of ProbeSkeleton for the particular framework. - */ - protected abstract ProbeSkeleton createProbe(Method method); - - /** - * Initializes the provider. - * - * @param type the user's interface - */ - protected ProviderSkeleton(Class type) { - this.active = false; // in case of some error during initialization - this.providerType = type; - this.probes = new HashMap(); - } - - /** - * Post-constructor initialization routine. - * - * Subclass instances must be initialized before they can create probes. - * It is up to the factory implementations to call this after construction. - */ - public void init() { - Method[] methods = AccessController.doPrivileged(new PrivilegedAction() { - public Method[] run() { - return providerType.getDeclaredMethods(); - } - }); - - for (Method m : methods) { - if ( m.getReturnType() != Void.TYPE ) { - throw new IllegalArgumentException( - "Return value of method is not void"); - } else { - probes.put(m, createProbe(m)); - } - } - this.active = true; - } - - /** - * Magic routine which creates an implementation of the user's interface. - * - * This method creates the instance of the user's interface which is - * passed back to the user. Every call upon that interface will be - * redirected to the {@code invoke()} method of this class (until - * overridden by the VM). - * - * @return an implementation of the user's interface - */ - @SuppressWarnings("unchecked") - public T newProxyInstance() { - final InvocationHandler ih = this; - return AccessController.doPrivileged(new PrivilegedAction() { - public T run() { - return (T)Proxy.newProxyInstance(providerType.getClassLoader(), - new Class[] { providerType }, ih); - }}); - } - - /** - * Triggers a framework probe when a user interface method is called. - * - * This method dispatches a user interface method call to the appropriate - * probe associated with this framework. - * - * If the invoked method is not a user-defined member of the interface, - * then it is a member of {@code Provider} or {@code Object} and we - * invoke the method directly. - * - * @param proxy the instance whose method was invoked - * @param method the method that was called - * @param args the arguments passed in the call. - * @return always null, if the method is a user-defined probe - */ - public Object invoke(Object proxy, Method method, Object[] args) { - Class declaringClass = method.getDeclaringClass(); - // not a provider subtype's own method - if (declaringClass != providerType) { - try { - // delegate only to methods declared by - // com.sun.tracing.Provider or java.lang.Object - if (declaringClass == Provider.class || - declaringClass == Object.class) { - return method.invoke(this, args); - } else { - // assert false : "this should never happen" - // reaching here would indicate a breach - // in security in the higher layers - throw new SecurityException(); - } - } catch (IllegalAccessException e) { - assert false; - } catch (InvocationTargetException e) { - assert false; - } - } else { - triggerProbe(method, args); - } - return null; - } - - /** - * Direct accessor for {@code Probe} objects. - * - * @param m the method corresponding to a probe - * @return the method associated probe object, or null - */ - public Probe getProbe(Method m) { - return active ? probes.get(m) : null; - } - - /** - * Default provider disposal method. - * - * This is overridden in subclasses as needed. - */ - public void dispose() { - active = false; - probes.clear(); - } - - /** - * Gets the user-specified provider name for the user's interface. - * - * If the user's interface has a {@ProviderName} annotation, that value - * is used. Otherwise we use the simple name of the user interface's class. - * @return the provider name - */ - protected String getProviderName() { - return getAnnotationString( - providerType, ProviderName.class, providerType.getSimpleName()); - } - - /** - * Utility method for getting a string value from an annotation. - * - * Used for getting a string value from an annotation with a 'value' method. - * - * @param element the element that was annotated, either a class or method - * @param annotation the class of the annotation we're interested in - * @param defaultValue the value to return if the annotation doesn't - * exist, doesn't have a "value", or the value is empty. - */ - protected static String getAnnotationString( - AnnotatedElement element, Class annotation, - String defaultValue) { - String ret = (String)getAnnotationValue( - element, annotation, "value", defaultValue); - return ret.isEmpty() ? defaultValue : ret; - } - - /** - * Utility method for calling an arbitrary method in an annotation. - * - * @param element the element that was annotated, either a class or method - * @param annotation the class of the annotation we're interested in - * @param methodName the name of the method in the annotation we wish - * to call. - * @param defaultValue the value to return if the annotation doesn't - * exist, or we couldn't invoke the method for some reason. - * @return the result of calling the annotation method, or the default. - */ - protected static Object getAnnotationValue( - AnnotatedElement element, Class annotation, - String methodName, Object defaultValue) { - Object ret = defaultValue; - try { - Method m = annotation.getMethod(methodName); - Annotation a = element.getAnnotation(annotation); - ret = m.invoke(a); - } catch (NoSuchMethodException e) { - assert false; - } catch (IllegalAccessException e) { - assert false; - } catch (InvocationTargetException e) { - assert false; - } catch (NullPointerException e) { - assert false; - } - return ret; - } - - protected void triggerProbe(Method method, Object[] args) { - if (active) { - ProbeSkeleton p = probes.get(method); - if (p != null) { - // Skips argument check -- already done by javac - p.uncheckedTrigger(args); - } - } - } -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/Activation.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/Activation.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing.dtrace; - -import java.lang.ref.WeakReference; -import java.lang.ref.ReferenceQueue; -import java.security.Permission; -import java.util.HashSet; - -class Activation { - private SystemResource resource; - private int referenceCount; - - Activation(String moduleName, DTraceProvider[] providers) { - SecurityManager security = System.getSecurityManager(); - if (security != null) { - Permission perm = - new RuntimePermission("com.sun.tracing.dtrace.createProvider"); - security.checkPermission(perm); - } - referenceCount = providers.length; - for (DTraceProvider p : providers) { - p.setActivation(this); - } - resource = new SystemResource( - this, JVM.activate(moduleName, providers)); - } - - void disposeProvider(DTraceProvider p) { - if (--referenceCount == 0) { - resource.dispose(); - } - } -} - -/** - * The native resource part of an Activation. - * - * This holds the native handle. - * - * If the user loses a reference to a set of Providers without disposing them, - * and GC determines the Activation is unreachable, then the next - * activation or flush call will automatically dispose the unreachable objects - * - * The SystemResource instances are creating during activation, and - * unattached during disposal. When created, they always have a - * strong reference to them via the {@code resources} static member. Explicit - * {@code dispose} calls will unregister the native resource and remove - * references to the SystemResource object. Absent an explicit dispose, - * when their associated Activation object becomes garbage, the SystemResource - * object will be enqueued on the reference queue and disposed at the - * next call to {@code flush}. - */ -class SystemResource extends WeakReference { - - private long handle; - - private static ReferenceQueue referenceQueue = - referenceQueue = new ReferenceQueue(); - static HashSet resources = new HashSet(); - - SystemResource(Activation activation, long handle) { - super(activation, referenceQueue); - this.handle = handle; - flush(); - resources.add(this); - } - - void dispose() { - JVM.dispose(handle); - resources.remove(this); - handle = 0; - } - - static void flush() { - SystemResource resource = null; - while ((resource = (SystemResource)referenceQueue.poll()) != null) { - if (resource.handle != 0) { - resource.dispose(); - } - } - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/DTraceProbe.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/DTraceProbe.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing.dtrace; - -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; - -import sun.tracing.ProbeSkeleton; - -class DTraceProbe extends ProbeSkeleton { - private Object proxy; - private Method declared_method; - private Method implementing_method; - - DTraceProbe(Object proxy, Method m) { - super(m.getParameterTypes()); - this.proxy = proxy; - this.declared_method = m; - try { - // The JVM will override the proxy method's implementation with - // a version that will invoke the probe. - this.implementing_method = proxy.getClass().getMethod( - m.getName(), m.getParameterTypes()); - } catch (NoSuchMethodException e) { - throw new RuntimeException("Internal error, wrong proxy class"); - } - } - - public boolean isEnabled() { - return JVM.isEnabled(implementing_method); - } - - public void uncheckedTrigger(Object[] args) { - try { - implementing_method.invoke(proxy, args); - } catch (IllegalAccessException e) { - assert false; - } catch (InvocationTargetException e) { - assert false; - } - } - - String getProbeName() { - return DTraceProvider.getProbeName(declared_method); - } - - String getFunctionName() { - return DTraceProvider.getFunctionName(declared_method); - } - - Method getMethod() { - return implementing_method; - } - - Class[] getParameterTypes() { - return this.parameters; - } -} - diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/DTraceProvider.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/DTraceProvider.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing.dtrace; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.annotation.Annotation; - -import sun.tracing.ProviderSkeleton; -import sun.tracing.ProbeSkeleton; -import com.sun.tracing.Provider; -import com.sun.tracing.ProbeName; -import com.sun.tracing.dtrace.Attributes; -import com.sun.tracing.dtrace.ModuleName; -import com.sun.tracing.dtrace.FunctionName; -import com.sun.tracing.dtrace.StabilityLevel; -import com.sun.tracing.dtrace.DependencyClass; - -import sun.misc.ProxyGenerator; - -class DTraceProvider extends ProviderSkeleton { - - private Activation activation; - private Object proxy; - - // For proxy generation - private final static Class[] constructorParams = { InvocationHandler.class }; - private final String proxyClassNamePrefix = "$DTraceTracingProxy"; - - static final String DEFAULT_MODULE = "java_tracing"; - static final String DEFAULT_FUNCTION = "unspecified"; - - private static long nextUniqueNumber = 0; - private static synchronized long getUniqueNumber() { - return nextUniqueNumber++; - } - - protected ProbeSkeleton createProbe(Method m) { - return new DTraceProbe(proxy, m); - } - - DTraceProvider(Class type) { - super(type); - } - - void setProxy(Object p) { - proxy = p; - } - - void setActivation(Activation a) { - this.activation = a; - } - - public void dispose() { - if (activation != null) { - activation.disposeProvider(this); - activation = null; - } - super.dispose(); - } - - /** - * Magic routine which creates an implementation of the user's interface. - * - * This method uses the ProxyGenerator directly to bypass the - * java.lang.reflect.proxy cache so that we get a unique class each - * time it's called and can't accidently reuse a $Proxy class. - * - * @return an implementation of the user's interface - */ - @SuppressWarnings("unchecked") - public T newProxyInstance() { - /* - * Choose a name for the proxy class to generate. - */ - long num = getUniqueNumber(); - - String proxyPkg = ""; - if (!Modifier.isPublic(providerType.getModifiers())) { - String name = providerType.getName(); - int n = name.lastIndexOf('.'); - proxyPkg = ((n == -1) ? "" : name.substring(0, n + 1)); - } - - String proxyName = proxyPkg + proxyClassNamePrefix + num; - - /* - * Generate the specified proxy class. - */ - Class proxyClass = null; - byte[] proxyClassFile = ProxyGenerator.generateProxyClass( - proxyName, new Class[] { providerType }); - try { - proxyClass = JVM.defineClass( - providerType.getClassLoader(), proxyName, - proxyClassFile, 0, proxyClassFile.length); - } catch (ClassFormatError e) { - /* - * A ClassFormatError here means that (barring bugs in the - * proxy class generation code) there was some other - * invalid aspect of the arguments supplied to the proxy - * class creation (such as virtual machine limitations - * exceeded). - */ - throw new IllegalArgumentException(e.toString()); - } - - /* - * Invoke its constructor with the designated invocation handler. - */ - try { - Constructor cons = proxyClass.getConstructor(constructorParams); - return (T)cons.newInstance(new Object[] { this }); - } catch (ReflectiveOperationException e) { - throw new InternalError(e.toString(), e); - } - } - - // In the normal case, the proxy object's method implementations will call - // this method (it usually calls the ProviderSkeleton's version). That - // method uses the passed 'method' object to lookup the associated - // 'ProbeSkeleton' and calls uncheckedTrigger() on that probe to cause the - // probe to fire. DTrace probes are different in that the proxy class's - // methods are immediately overridden with native code to fire the probe - // directly. So this method should never get invoked. We also wire up the - // DTraceProbe.uncheckedTrigger() method to call the proxy method instead - // of doing the work itself. - protected void triggerProbe(Method method, Object[] args) { - assert false : "This method should have been overridden by the JVM"; - } - - public String getProviderName() { - return super.getProviderName(); - } - - String getModuleName() { - return getAnnotationString( - providerType, ModuleName.class, DEFAULT_MODULE); - } - - static String getProbeName(Method method) { - return getAnnotationString( - method, ProbeName.class, method.getName()); - } - - static String getFunctionName(Method method) { - return getAnnotationString( - method, FunctionName.class, DEFAULT_FUNCTION); - } - - DTraceProbe[] getProbes() { - return probes.values().toArray(new DTraceProbe[0]); - } - - StabilityLevel getNameStabilityFor(Class type) { - Attributes attrs = (Attributes)getAnnotationValue( - providerType, type, "value", null); - if (attrs == null) { - return StabilityLevel.PRIVATE; - } else { - return attrs.name(); - } - } - - StabilityLevel getDataStabilityFor(Class type) { - Attributes attrs = (Attributes)getAnnotationValue( - providerType, type, "value", null); - if (attrs == null) { - return StabilityLevel.PRIVATE; - } else { - return attrs.data(); - } - } - - DependencyClass getDependencyClassFor(Class type) { - Attributes attrs = (Attributes)getAnnotationValue( - providerType, type, "value", null); - if (attrs == null) { - return DependencyClass.UNKNOWN; - } else { - return attrs.dependency(); - } - } -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/DTraceProviderFactory.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/DTraceProviderFactory.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2008, 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 sun.tracing.dtrace; - -import java.util.Map; -import java.util.Set; -import java.util.HashMap; -import java.util.HashSet; -import java.security.Permission; - -import com.sun.tracing.ProviderFactory; -import com.sun.tracing.Provider; - -/** - * Factory class to create JSDT Providers. - * - * This class contains methods to create an instance of a Provider - * interface which can be used to place tracepoints in an application. - * Method calls upon that instance trigger DTrace probes that - * are visible from DTrace scripts. Such calls have no other - * side effects in the application. - *

- * The DTrace script mechanisms for listing and matching probes will not see - * nor match any probes until the provider they reside in is created by a - * call to {@code createProvider()} (or {@code createProviders()}). - *

- * Providers that are created should be disposed of when they are no longer - * needed to free up system resources, at which point the associated - * DTrace probes will no longer be available to DTrace. One disposes a - * provider by calling - * {@link com.sun.tracing.Provider#dispose Provider.dispose()} on a - * created provider instance. - * - * @since 1.7 - */ -public final class DTraceProviderFactory extends ProviderFactory { - /** - * Creates an instance of a provider which can then be used to trigger - * DTrace probes. - * - * The provider specification, provided as an argument, should only - * contain methods which have a 'void' return type and String or - * integer-based typed arguments (long, int, short, char, byte, or boolean). - * - * @param cls A user-defined interface which extends {@code Provider}. - * @return An instance of the interface which is used to trigger - * the DTrace probes. - * @throws java.lang.SecurityException if a security manager has been - * installed and it denies - * RuntimePermission("com.sun.dtrace.jsdt.createProvider") - * @throws java.lang.IllegalArgumentException if the interface contains - * methods that do not return null, or that contain arguments that are - * not String or integer types. - */ - public T createProvider(Class cls) { - DTraceProvider jsdt = new DTraceProvider(cls); - T proxy = jsdt.newProxyInstance(); - jsdt.setProxy(proxy); - jsdt.init(); - new Activation(jsdt.getModuleName(), new DTraceProvider[] { jsdt }); - return proxy; - } - - /** - * Creates multiple providers at once. - * - * This method batches together a number of provider instantiations. - * It works similarly - * to {@code createProvider}, but operates on a set of providers instead - * of one at a time. This method is in place since some DTrace - * implementations limit the number of times that providers can be - * created. When numerous providers can be created at once with this - * method, it will count only as a single creation point to DTrace, thus - * it uses less system resources. - *

- * All of the probes in the providers will be visible to DTrace after - * this call and all will remain visible until all of the providers - * are disposed. - *

- * The {@code moduleName} parameter will override any {@code ModuleName} - * annotation associated with any of the providers in the set. - * All of the probes created by this call will share the same - * module name. - *

- * @param providers a set of provider specification interfaces - * @param moduleName the module name to associate with all probes - * @return A map which maps the provider interface specification to an - * implementing instance. - * @throws java.lang.SecurityException if a security manager has been - * installed and it denies - * RuntimePermission("com.sun.dtrace.jsdt.createProvider") - * @throws java.lang.IllegalArgumentException if any of the interface - * contains methods that do not return null, or that contain arguments - * that are not String or integer types. - */ - public Map,Provider> createProviders( - Set> providers, String moduleName) { - HashMap,Provider> map = - new HashMap,Provider>(); - HashSet jsdts = new HashSet(); - for (Class cls : providers) { - DTraceProvider jsdt = new DTraceProvider(cls); - jsdts.add(jsdt); - map.put(cls, jsdt.newProxyInstance()); - } - new Activation(moduleName, jsdts.toArray(new DTraceProvider[0])); - return map; - } - - /** - * Used to check the status of DTrace support in the underlying JVM and - * operating system. - * - * This is an informative method only - the Java-level effects of - * creating providers and triggering probes will not change whether or - * not DTrace is supported by the underlying systems. - * - * @return true if DTrace is supported - */ - public static boolean isSupported() { - try { - SecurityManager security = System.getSecurityManager(); - if (security != null) { - Permission perm = new RuntimePermission( - "com.sun.tracing.dtrace.createProvider"); - security.checkPermission(perm); - } - return JVM.isSupported(); - } catch (SecurityException e) { - return false; - } - } -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/JVM.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/dtrace/JVM.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2008, 2012, 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 sun.tracing.dtrace; - -import java.lang.reflect.Method; - -/** - * Container class for JVM interface native methods - * - * @since 1.7 - */ -class JVM { - - static { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("jsdt"); - return null; - } - }); - } - - static long activate(String moduleName, DTraceProvider[] providers) { - return activate0(moduleName, providers); - } - - static void dispose(long handle) { - dispose0(handle); - } - - static boolean isEnabled(Method m) { - return isEnabled0(m); - } - - static boolean isSupported() { - return isSupported0(); - } - - static Class defineClass( - ClassLoader loader, String name, byte[] b, int off, int len) { - return defineClass0(loader, name, b, off, len); - } - - private static native long activate0( - String moduleName, DTraceProvider[] providers); - private static native void dispose0(long activation_handle); - private static native boolean isEnabled0(Method m); - private static native boolean isSupported0(); - private static native Class defineClass0( - ClassLoader loader, String name, byte[] b, int off, int len); -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/classes/sun/tracing/package-info.java --- a/jdk/src/jdk.runtime/share/classes/sun/tracing/package-info.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008, 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. - */ - -/** - * This package contains internal common code for implementing tracing - * frameworks, and defined a number of existing frameworks. - *

- * There are four tracing frameworks currently defined. The "Null" and - * "Multiplex" frameworks are used internally as part of the implementation. - * The "DTrace" framework is the prime consumer framework at the moment, - * while the "PrintStream" framework is a functional, but hidden, framework - * which can be used to track probe firings. All but the "DTrace" framework - * are defined in this package. The "DTrace" framework is implemented in the - * {@code sun.tracing.dtrace} package. - *

- * This package also contains the {@code ProviderSkeleton} class, which - * holds most of the common code needed for implementing frameworks. - *

- * The "Null" framework is used when there are no other active frameworks. - * It accomplishes absolutely nothing and is merely a placeholder so that - * the application can call the tracing routines without error. - *

- * The "Multiplex" framework is used when there are multiple active frameworks. - * It is initialized with the framework factories and create providers and - * probes that dispatch to each active framework in turn. - *

- * The "PrintStream" framework is currently a debugging framework which - * dispatches trace calls to a user-defined PrintStream class, defined by - * a property. It may some day be opened up to general use. - *

- * See the {@code sun.tracing.dtrace} and {@code com.sun.tracing.dtrace} - * packages for information on the "DTrace" framework. - */ - -package sun.tracing; diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/native/libjsdt/JVM.c --- a/jdk/src/jdk.runtime/share/native/libjsdt/JVM.c Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,334 +0,0 @@ -/* - * Copyright (c) 2008, 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. - */ - -#include - -#include "jvm.h" -#include "jni.h" -#include "jni_util.h" - -#include "jvm_symbols.h" -#include "sun_tracing_dtrace_JVM.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static JvmSymbols* jvm_symbols = NULL; - -static void initialize() { - static int initialized = 0; - if (initialized == 0) { - jvm_symbols = lookupJvmSymbols(); - initialized = 1; - } -} - -/* - * Class: sun_tracing_dtrace_JVM - * Method: isSupported0 - * Signature: ()I - */ -JNIEXPORT jboolean JNICALL Java_sun_tracing_dtrace_JVM_isSupported0( - JNIEnv* env, jclass cls) { - initialize(); - if (jvm_symbols != NULL) { - return jvm_symbols->IsSupported(env) ? JNI_TRUE : JNI_FALSE; - } else { - return JNI_FALSE; - } -} - -// Macros that cause an immediate return if we detect an exception -#define CHECK if ((*env)->ExceptionOccurred(env)) { return; } -#define CHECK_(x) if ((*env)->ExceptionOccurred(env)) { return x; } - -static void readProbeData ( - JNIEnv* env, jobject probe, JVM_DTraceProbe* jvm_probe) { - jclass clazz; - jmethodID mid; - jobject method; - - if (jvm_probe == NULL) { - return; // just in case - } - - clazz = (*env)->GetObjectClass(env, probe); CHECK - - mid = (*env)->GetMethodID( - env, clazz, "getFunctionName", "()Ljava/lang/String;"); CHECK - jvm_probe->function = (jstring)(*env)->CallObjectMethod( - env, probe, mid); CHECK - - mid = (*env)->GetMethodID( - env, clazz, "getProbeName", "()Ljava/lang/String;"); CHECK - jvm_probe->name = (jstring)(*env)->CallObjectMethod(env, probe, mid); CHECK - - mid = (*env)->GetMethodID( - env, clazz, "getMethod", "()Ljava/lang/reflect/Method;"); CHECK - method = (*env)->CallObjectMethod(env, probe, mid); CHECK - jvm_probe->method = (*env)->FromReflectedMethod(env, method); CHECK -} - -static void readFieldInterfaceAttributes( - char* annotationName, JNIEnv* env, jobject provider, - JVM_DTraceInterfaceAttributes* attrs) { - jobject result; - jobject result_clazz; - jclass provider_clazz; - jclass annotation_clazz; - jmethodID get; - jmethodID enc; - - provider_clazz = (*env)->GetObjectClass(env, provider); CHECK - annotation_clazz = (*env)->FindClass(env, annotationName); CHECK - - get = (*env)->GetMethodID(env, provider_clazz, "getNameStabilityFor", - "(Ljava/lang/Class;)Lcom/sun/tracing/dtrace/StabilityLevel;"); CHECK - result = (*env)->CallObjectMethod( - env, provider, get, annotation_clazz); CHECK - result_clazz = (*env)->GetObjectClass(env, result); CHECK - enc = (*env)->GetMethodID(env, result_clazz, "getEncoding", "()I"); CHECK - attrs->nameStability = (*env)->CallIntMethod(env, result, enc); CHECK - - get = (*env)->GetMethodID(env, provider_clazz, "getDataStabilityFor", - "(Ljava/lang/Class;)Lcom/sun/tracing/dtrace/StabilityLevel;"); CHECK - result = (*env)->CallObjectMethod( - env, provider, get, annotation_clazz); CHECK - result_clazz = (*env)->GetObjectClass(env, result); CHECK - enc = (*env)->GetMethodID(env, result_clazz, "getEncoding", "()I"); CHECK - attrs->dataStability = (*env)->CallIntMethod(env, result, enc); CHECK - - get = (*env)->GetMethodID(env, provider_clazz, "getDependencyClassFor", - "(Ljava/lang/Class;)Lcom/sun/tracing/dtrace/DependencyClass;"); CHECK - result = (*env)->CallObjectMethod( - env, provider, get, annotation_clazz); CHECK - result_clazz = (*env)->GetObjectClass(env, result); CHECK - enc = (*env)->GetMethodID(env, result_clazz, "getEncoding", "()I"); CHECK - attrs->dependencyClass = (*env)->CallIntMethod(env, result, enc); CHECK -} - -static void readInterfaceAttributes( - JNIEnv* env, jobject provider, JVM_DTraceProvider* jvm_provider) { - readFieldInterfaceAttributes("com/sun/tracing/dtrace/ProviderAttributes", - env, provider, &(jvm_provider->providerAttributes)); - readFieldInterfaceAttributes("com/sun/tracing/dtrace/ModuleAttributes", - env, provider, &(jvm_provider->moduleAttributes)); - readFieldInterfaceAttributes("com/sun/tracing/dtrace/FunctionAttributes", - env, provider, &(jvm_provider->functionAttributes)); - readFieldInterfaceAttributes("com/sun/tracing/dtrace/NameAttributes", - env, provider, &(jvm_provider->nameAttributes)); - readFieldInterfaceAttributes("com/sun/tracing/dtrace/ArgsAttributes", - env, provider, &(jvm_provider->argsAttributes)); -} - -static int readProviderData( - JNIEnv* env, jobject provider, JVM_DTraceProvider* jvm_provider) { - jmethodID mid; - jobjectArray probes; - jsize i; - jclass clazz = (*env)->GetObjectClass(env, provider); CHECK_(0) - mid = (*env)->GetMethodID( - env, clazz, "getProbes", "()[Lsun/tracing/dtrace/DTraceProbe;"); CHECK_(0) - probes = (jobjectArray)(*env)->CallObjectMethod( - env, provider, mid); CHECK_(0) - - // Fill JVM structure, describing provider - jvm_provider->probe_count = (*env)->GetArrayLength(env, probes); CHECK_(0) - jvm_provider->probes = (JVM_DTraceProbe*)calloc( - jvm_provider->probe_count, sizeof(*jvm_provider->probes)); - mid = (*env)->GetMethodID( - env, clazz, "getProviderName", "()Ljava/lang/String;"); CHECK_(0) - jvm_provider->name = (jstring)(*env)->CallObjectMethod( - env, provider, mid); CHECK_(0) - - readInterfaceAttributes(env, provider, jvm_provider); CHECK_(0) - - for (i = 0; i < jvm_provider->probe_count; ++i) { - jobject probe = (*env)->GetObjectArrayElement(env, probes, i); CHECK_(0) - readProbeData(env, probe, &jvm_provider->probes[i]); CHECK_(0) - } - - return 1; -} - -/* - * Class: sun_tracing_dtrace_JVM - * Method: activate0 - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_sun_tracing_dtrace_JVM_activate0( - JNIEnv* env, jclass cls, jstring moduleName, jobjectArray providers) { - jlong handle = 0; - jsize num_providers; - jsize i; - jsize count = 0; - JVM_DTraceProvider* jvm_providers; - - initialize(); - - if (jvm_symbols == NULL) { - return 0; - } - - num_providers = (*env)->GetArrayLength(env, providers); CHECK_(0L) - - jvm_providers = (JVM_DTraceProvider*)calloc( - num_providers, sizeof(*jvm_providers)); - - for (; count < num_providers; ++count) { - JVM_DTraceProvider* p = &(jvm_providers[count]); - jobject provider = (*env)->GetObjectArrayElement( - env, providers, count); - if ((*env)->ExceptionOccurred(env) || - ! readProviderData(env, provider, p)) { - // got an error, bail out! - break; - } - } - - if (count == num_providers) { - // all providers successfully loaded - get the handle - handle = jvm_symbols->Activate( - env, JVM_TRACING_DTRACE_VERSION, moduleName, - num_providers, jvm_providers); - } - - for (i = 0; i < num_providers; ++i) { - JVM_DTraceProvider* p = &(jvm_providers[i]); - free(p->probes); - } - free(jvm_providers); - - return handle; -} - -/* - * Class: sun_tracing_dtrace_JVM - * Method: dispose0 - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_tracing_dtrace_JVM_dispose0( - JNIEnv* env, jclass cls, jlong handle) { - if (jvm_symbols != NULL && handle != 0) { - jvm_symbols->Dispose(env, handle); - } -} - -/* - * Class: sun_tracing_dtrace_JVM - * Method: isEnabled0 - * Signature: (Ljava/lang/String;Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_tracing_dtrace_JVM_isEnabled0( - JNIEnv* env, jclass cls, jobject method) { - jmethodID mid; - if (jvm_symbols != NULL && method != NULL) { - mid = (*env)->FromReflectedMethod(env, method); - return jvm_symbols->IsProbeEnabled(env, mid); - } - return JNI_FALSE; -} - -/* - * Class: sun_tracing_dtrace_JVM - * Method: defineClass0 - * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class; - * - * The implementation of this native static method is a copy of that of - * the native instance method Java_java_lang_ClassLoader_defineClass0() - * with the implicit "this" parameter becoming the "loader" parameter. - * - * This code was cloned and modified from java_lang_reflect_Proxy - */ -JNIEXPORT jclass JNICALL -Java_sun_tracing_dtrace_JVM_defineClass0( - JNIEnv *env, jclass ignore, jobject loader, jstring name, jbyteArray data, - jint offset, jint length) -{ - jbyte *body; - char *utfName; - jclass result = 0; - char buf[128]; - - if (data == NULL) { - return 0; - } - - /* Work around 4153825. malloc crashes on Solaris when passed a - * negative size. - */ - if (length < 0) { - return 0; - } - - body = (jbyte *)malloc(length); - - if (body == 0) { - return 0; - } - - (*env)->GetByteArrayRegion(env, data, offset, length, body); - - if ((*env)->ExceptionOccurred(env)) - goto free_body; - - if (name != NULL) { - int i; - jsize len = (*env)->GetStringUTFLength(env, name); - int unicode_len = (*env)->GetStringLength(env, name); - if (len >= (jsize)sizeof(buf)) { - utfName = malloc(len + 1); - if (utfName == NULL) { - goto free_body; - } - } else { - utfName = buf; - } - (*env)->GetStringUTFRegion(env, name, 0, unicode_len, utfName); - - // Convert '.' to '/' in the package name - for (i = 0; i < unicode_len; ++i) { - if (utfName[i] == '.') { - utfName[i] = '/'; - } - } - } else { - utfName = NULL; - } - - result = (*env)->DefineClass(env, utfName, loader, body, length); - - if (utfName && utfName != buf) - free(utfName); - - free_body: - free(body); - return result; -} - -#ifdef __cplusplus -} -#endif diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/share/native/libjsdt/jvm_symbols.h --- a/jdk/src/jdk.runtime/share/native/libjsdt/jvm_symbols.h Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2008, 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. - */ - -#ifndef _JVM_SYMBOLS_H -#define _JVM_SYMBOLS_H - -#include "jvm.h" - -typedef jint (JNICALL* GetVersion_t)(JNIEnv*); -typedef jboolean (JNICALL *IsSupported_t)(JNIEnv*); -typedef jlong (JNICALL* Activate_t)( - JNIEnv*, jint, jstring, jint, JVM_DTraceProvider*); -typedef void (JNICALL *Dispose_t)(JNIEnv*, jlong); -typedef jboolean (JNICALL *IsProbeEnabled_t)(JNIEnv*, jmethodID); - -typedef struct { - GetVersion_t GetVersion; - IsSupported_t IsSupported; - Activate_t Activate; - Dispose_t Dispose; - IsProbeEnabled_t IsProbeEnabled; -} JvmSymbols; - -// Platform-dependent implementation. -// Returns NULL if the symbols are not found -extern JvmSymbols* lookupJvmSymbols(); - -#endif // def _JVM_SYMBOLS_H diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/unix/native/libjsdt/jvm_symbols_md.c --- a/jdk/src/jdk.runtime/unix/native/libjsdt/jvm_symbols_md.c Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2008, 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. - */ - -#include -#include - -#include - -#include "jvm_symbols.h" - -JvmSymbols* lookupJvmSymbols() { - JvmSymbols* syms = (JvmSymbols*)malloc(sizeof(JvmSymbols)); - if (syms != NULL) { - syms->GetVersion = (GetVersion_t) - dlsym(RTLD_DEFAULT, "JVM_DTraceGetVersion"); - syms->IsSupported = (IsSupported_t) - dlsym(RTLD_DEFAULT, "JVM_DTraceIsSupported"); - syms->Activate = (Activate_t) - dlsym(RTLD_DEFAULT, "JVM_DTraceActivate"); - syms->Dispose = (Dispose_t) - dlsym(RTLD_DEFAULT, "JVM_DTraceDispose"); - syms->IsProbeEnabled = (IsProbeEnabled_t) - dlsym(RTLD_DEFAULT, "JVM_DTraceIsProbeEnabled"); - - if ( syms->GetVersion == NULL || syms->Activate == NULL || - syms->IsProbeEnabled == NULL || syms->Dispose == NULL || - syms->IsSupported == NULL) { - free(syms); - syms = NULL; - } - } - return syms; -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/src/jdk.runtime/windows/native/libjsdt/jvm_symbols_md.c --- a/jdk/src/jdk.runtime/windows/native/libjsdt/jvm_symbols_md.c Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2008, 2011, 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. - */ - -#include -#include -#include -#include - -#include - -#include "jvm_symbols.h" - -JvmSymbols* lookupJvmSymbols() { - JvmSymbols* syms = (JvmSymbols*)malloc(sizeof(JvmSymbols)); - if (syms != NULL) { - HINSTANCE jvm = GetModuleHandle("jvm.dll"); - if (jvm == NULL) { - free(syms); - return NULL; - } - syms->GetVersion = (GetVersion_t) - GetProcAddress(jvm, "JVM_DTraceGetVersion"); - syms->IsSupported = (IsSupported_t) - GetProcAddress(jvm, "JVM_DTraceIsSupported"); - syms->Activate = (Activate_t) - GetProcAddress(jvm, "JVM_DTraceActivate"); - syms->Dispose = (Dispose_t) - GetProcAddress(jvm, "JVM_DTraceDispose"); - syms->IsProbeEnabled = (IsProbeEnabled_t) - GetProcAddress(jvm, "JVM_DTraceIsProbeEnabled"); - - (void)FreeLibrary(jvm); - if ( syms->GetVersion == NULL || syms->IsSupported == NULL || - syms->Activate == NULL || syms->Dispose == NULL || - syms->IsProbeEnabled == NULL) { - free(syms); - syms = NULL; - } - - } - return syms; -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/test/ProblemList.txt --- a/jdk/test/ProblemList.txt Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/test/ProblemList.txt Mon Feb 16 08:47:40 2015 -0800 @@ -141,9 +141,6 @@ # 8058492 java/lang/management/ThreadMXBean/FindDeadlocks.java generic-all -# 8069286 -java/lang/management/MemoryMXBean/LowMemoryTest.java generic-all - ############################################################################ # jdk_jmx @@ -352,7 +349,4 @@ # 8064572 8060736 8062938 sun/jvmstat/monitor/MonitoredVm/CR6672135.java generic-all -# 8060088 -com/sun/tracing/BasicWithSecurityMgr.java generic-all - ############################################################################ diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/test/TEST.groups --- a/jdk/test/TEST.groups Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/test/TEST.groups Mon Feb 16 08:47:40 2015 -0800 @@ -190,7 +190,6 @@ svc_tools = \ com/sun/tools/attach \ - com/sun/tracing \ sun/tools \ -sun/tools/java \ -sun/tools/native2ascii \ @@ -562,7 +561,6 @@ com/sun/security/auth \ com/sun/security/sasl \ com/sun/security/jgss \ - com/sun/tracing \ java/util/prefs \ javax/naming \ javax/security \ diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/test/com/sun/tracing/BasicFunctionality.java --- a/jdk/test/com/sun/tracing/BasicFunctionality.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * @test - * @bug 6537506 - * @ignore 6962535 - * @summary Basic unit test for tracing framework - */ - -import com.sun.tracing.*; -import java.lang.reflect.Method; - -@ProviderName("NamedProvider") -interface BasicProvider extends Provider { - void plainProbe(); - void probeWithArgs(int a, float f, String s, Long l); - @ProbeName("namedProbe") void probeWithName(); - void overloadedProbe(); - void overloadedProbe(int i); -} - -interface InvalidProvider extends Provider { - int nonVoidProbe(); -} - -public class BasicFunctionality { - - public static ProviderFactory factory; - public static BasicProvider bp; - - public static void main(String[] args) throws Exception { - - factory = ProviderFactory.getDefaultFactory(); - if (factory != null) { - bp = factory.createProvider(BasicProvider.class); - } - - testProviderFactory(); - testProbe(); - testProvider(); - } - - static void fail(String s) throws Exception { - throw new Exception(s); - } - - static void testProviderFactory() throws Exception { - if (factory == null) { - fail("ProviderFactory.getDefaultFactory: Did not create factory"); - } - if (bp == null) { - fail("ProviderFactory.createProvider: Did not create provider"); - } - try { - factory.createProvider(null); - fail("ProviderFactory.createProvider: Did not throw NPE for null"); - } catch (NullPointerException e) {} - - try { - factory.createProvider(InvalidProvider.class); - fail("Factory.createProvider: Should error with non-void probes"); - } catch (IllegalArgumentException e) {} - } - - public static void testProvider() throws Exception { - - // These just shouldn't throw any exeptions: - bp.plainProbe(); - bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L)); - bp.probeWithArgs(42, (float)3.14, null, null); - bp.probeWithName(); - bp.overloadedProbe(); - bp.overloadedProbe(42); - - Method m = BasicProvider.class.getMethod("plainProbe"); - Probe p = bp.getProbe(m); - if (p == null) { - fail("Provider.getProbe: Did not return probe"); - } - - Method m2 = BasicFunctionality.class.getMethod("testProvider"); - p = bp.getProbe(m2); - if (p != null) { - fail("Provider.getProbe: Got probe with invalid spec"); - } - - bp.dispose(); - // These just shouldn't throw any exeptions: - bp.plainProbe(); - bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L)); - bp.probeWithArgs(42, (float)3.14, null, null); - bp.probeWithName(); - bp.overloadedProbe(); - bp.overloadedProbe(42); - - if (bp.getProbe(m) != null) { - fail("Provider.getProbe: Should return null after dispose()"); - } - - bp.dispose(); // just to make sure nothing bad happens - } - - static void testProbe() throws Exception { - Method m = BasicProvider.class.getMethod("plainProbe"); - Probe p = bp.getProbe(m); - p.isEnabled(); // just make sure it doesn't do anything bad - p.trigger(); - - try { - p.trigger(0); - fail("Probe.trigger: too many arguments not caught"); - } catch (IllegalArgumentException e) {} - - p = bp.getProbe(BasicProvider.class.getMethod( - "probeWithArgs", int.class, float.class, String.class, Long.class)); - try { - p.trigger(); - fail("Probe.trigger: too few arguments not caught"); - } catch (IllegalArgumentException e) {} - - try { - p.trigger((float)3.14, (float)3.14, "", new Long(0L)); - fail("Probe.trigger: wrong type primitive arguments not caught"); - } catch (IllegalArgumentException e) {} - } -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/test/com/sun/tracing/BasicWithSecurityMgr.java --- a/jdk/test/com/sun/tracing/BasicWithSecurityMgr.java Mon Feb 16 00:10:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * @test - * @bug 6899605 - * @summary Basic unit test for tracing framework with security manager - * enabled - */ - -import com.sun.tracing.*; -import java.lang.reflect.Method; - -@ProviderName("NamedProvider") -interface BasicProvider extends Provider { - void plainProbe(); - void probeWithArgs(int a, float f, String s, Long l); - @ProbeName("namedProbe") void probeWithName(); - void overloadedProbe(); - void overloadedProbe(int i); -} - -interface InvalidProvider extends Provider { - int nonVoidProbe(); -} - -public class BasicWithSecurityMgr { - - public static ProviderFactory factory; - public static BasicProvider bp; - - public static void main(String[] args) throws Exception { - // enable security manager - System.setSecurityManager(new SecurityManager()); - - factory = ProviderFactory.getDefaultFactory(); - if (factory != null) { - bp = factory.createProvider(BasicProvider.class); - } - - testProviderFactory(); - testProbe(); - testProvider(); - } - - static void fail(String s) throws Exception { - throw new Exception(s); - } - - static void testProviderFactory() throws Exception { - if (factory == null) { - fail("ProviderFactory.getDefaultFactory: Did not create factory"); - } - if (bp == null) { - fail("ProviderFactory.createProvider: Did not create provider"); - } - try { - factory.createProvider(null); - fail("ProviderFactory.createProvider: Did not throw NPE for null"); - } catch (NullPointerException e) {} - - try { - factory.createProvider(InvalidProvider.class); - fail("Factory.createProvider: Should error with non-void probes"); - } catch (IllegalArgumentException e) {} - } - - public static void testProvider() throws Exception { - - // These just shouldn't throw any exeptions: - bp.plainProbe(); - bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L)); - bp.probeWithArgs(42, (float)3.14, null, null); - bp.probeWithName(); - bp.overloadedProbe(); - bp.overloadedProbe(42); - - Method m = BasicProvider.class.getMethod("plainProbe"); - Probe p = bp.getProbe(m); - if (p == null) { - fail("Provider.getProbe: Did not return probe"); - } - - Method m2 = BasicWithSecurityMgr.class.getMethod("testProvider"); - p = bp.getProbe(m2); - if (p != null) { - fail("Provider.getProbe: Got probe with invalid spec"); - } - - bp.dispose(); - // These just shouldn't throw any exeptions: - bp.plainProbe(); - bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L)); - bp.probeWithArgs(42, (float)3.14, null, null); - bp.probeWithName(); - bp.overloadedProbe(); - bp.overloadedProbe(42); - - if (bp.getProbe(m) != null) { - fail("Provider.getProbe: Should return null after dispose()"); - } - - bp.dispose(); // just to make sure nothing bad happens - } - - static void testProbe() throws Exception { - Method m = BasicProvider.class.getMethod("plainProbe"); - Probe p = bp.getProbe(m); - p.isEnabled(); // just make sure it doesn't do anything bad - p.trigger(); - - try { - p.trigger(0); - fail("Probe.trigger: too many arguments not caught"); - } catch (IllegalArgumentException e) {} - - p = bp.getProbe(BasicProvider.class.getMethod( - "probeWithArgs", int.class, float.class, String.class, Long.class)); - try { - p.trigger(); - fail("Probe.trigger: too few arguments not caught"); - } catch (IllegalArgumentException e) {} - - try { - p.trigger((float)3.14, (float)3.14, "", new Long(0L)); - fail("Probe.trigger: wrong type primitive arguments not caught"); - } catch (IllegalArgumentException e) {} - } -} diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java --- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java Mon Feb 16 00:10:42 2015 +0000 +++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java Mon Feb 16 08:47:40 2015 -0800 @@ -32,8 +32,7 @@ * * @library /lib/testlibrary/ * @build jdk.testlibrary.* LowMemoryTest MemoryUtil RunUtil - * @requires vm.opt.ExplicitGCInvokesConcurrent == "false" | vm.opt.ExplicitGCInvokesConcurrent == "null" - * @run main/timeout=600 LowMemoryTest + * @run main/timeout=600 LowMemoryTest * @requires vm.opt.ExplicitGCInvokesConcurrent != "true" * @requires vm.opt.ExplicitGCInvokesConcurrentAndUnloadsClasses != "true" * @requires vm.opt.DisableExplicitGC != "true" @@ -116,14 +115,13 @@ triggers++; } public void checkResult() throws Exception { - if ((!isRelaxed && triggers != NUM_TRIGGERS) || - (isRelaxed && triggers < NUM_TRIGGERS)) { + if (!checkValue(triggers, NUM_TRIGGERS)) { throw new RuntimeException("Unexpected number of triggers = " + triggers + " but expected to be " + NUM_TRIGGERS); } for (int i = 0; i < triggers; i++) { - if (count[i] != i+1) { + if (!checkValue(count[i], i + 1)) { throw new RuntimeException("Unexpected count of" + " notification #" + i + " count = " + count[i] + @@ -136,6 +134,18 @@ } } } + + private boolean checkValue(int value, int target) { + return checkValue((long)value, target); + } + + private boolean checkValue(long value, int target) { + if (!isRelaxed) { + return value == target; + } else { + return value >= target; + } + } } private static long newThreshold; diff -r 7a1ceff4aea2 -r e70dcf797a33 jdk/test/java/security/ProtectionDomain/PreserveCombinerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/security/ProtectionDomain/PreserveCombinerTest.java Mon Feb 16 08:47:40 2015 -0800 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 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. + * + * 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 java.security.AccessControlContext; +import java.security.AccessController; +import java.security.DomainCombiner; +import java.security.PrivilegedAction; +import java.security.ProtectionDomain; +import sun.misc.SharedSecrets; + +/* + * @test + * @bug 8064331 + * @summary Make sure that JavaSecurityAccess.doIntersectionPrivilege() + * is not dropping the information about the domain combiner of + * the stack ACC + */ + +public class PreserveCombinerTest { + public static void main(String[]args) throws Exception { + final DomainCombiner dc = new DomainCombiner() { + @Override + public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) { + return currentDomains; // basically a no-op + } + }; + + // Get an instance of the saved ACC + AccessControlContext saved = AccessController.getContext(); + // Simulate the stack ACC with a DomainCombiner attached + AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc); + + // Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert + // whether the DomainCombiner from the stack ACC is preserved + boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction() { + @Override + public Boolean run() { + return dc == AccessController.getContext().getDomainCombiner(); + } + }, stack, saved); + + if (!ret) { + System.exit(1); + } + } +} +