{"id":216435,"date":"2014-03-19T22:31:03","date_gmt":"2014-03-19T18:31:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=216435"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=216435","title":{"rendered":"<span class=\"post_title\">\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c reflection \u0432 JDK8 \u0438 JDK7<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e, \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0443\u044f \u043f\u043e \u043a\u043e\u0434\u0443 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430\u0431\u0440\u0435\u043b \u043d\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 spring \u0431\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (\u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043b\u0435\u0442\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432) \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 reflection. \u0412 \u0431\u0438\u043d\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u044d\u0448 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432, \u043e\u0434\u043d\u0430\u043a\u043e \u044f \u0437\u0430\u0434\u0430\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u2014 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440 reflection \u0438 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/74d\/574\/e80\/74d574e800e2413c2c803094efde750a.png\"\/><br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0421 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0440\u0443\u043a\u0438 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043c\u0438\u043a\u0440\u043e\u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a \u043d\u0430 JMH, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u0438\u043a\u0440\u043e\u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u2014 \u0434\u0435\u043b\u043e \u043d\u0435\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0438 \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b. \u0422\u0430\u043a \u044f \u0443\u043f\u0443\u0441\u0442\u0438\u043b \u0438\u0437 \u0433\u043e\u043b\u043e\u0432\u044b \u0431\u043e\u043a\u0441\u0438\u043d\u0433-\u0430\u043d\u0431\u043e\u043a\u0441\u0438\u043d\u0433 \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0438\u0437\u043c\u0435\u0440\u044f\u043b \u0435\u0433\u043e, \u0430 \u043d\u0435 \u0441\u0430\u043c \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430. \u0410 \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0432\u043e\u044e \u043d\u0430\u0448\u0435\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b PrintAssembly.<\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 reflection \u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0441\u043e\u0431\u0440\u0430\u043b\u0441\u044f \u0443\u0431\u0440\u0430\u0442\u044c \u0438\u0445 \u0432 \u044f\u0449\u0438\u043a \u0434\u043e \u043b\u0443\u0447\u0448\u0438\u0445 \u0432\u0440\u0435\u043c\u0435\u043d, \u043d\u043e \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043b\u0435\u043d\u0442\u0443 \u0442\u0432\u0438\u0442\u0442\u0435\u0440\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439, \u0440\u0430\u0437\u0431\u0430\u0432\u0438\u043b\u0438 \u0442\u0432\u0438\u0442\u044b \u043f\u0440\u043e \u0440\u0435\u043b\u0438\u0437 java8. \u041e\u0431\u0443\u0437\u0434\u0430\u0432 \u0440\u0430\u0434\u043e\u0441\u0442\u044c, \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c reflection \u0432 JDK7 \u0438 JDK8.<\/p>\n<p>  \u041a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433\u0430 JMH:   <\/p>\n<ul>\n<li>Benchmark \u2014 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e @GenerateMicroBenchmark<\/li>\n<li>Mode \u2014 \u0440\u0435\u0436\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430, \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 thrpt \u2014 Throughput, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2014 \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 1s<\/li>\n<li>Samples \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439<\/li>\n<li>Mean \u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/li>\n<li>Mean error \u2014 c\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>Units \u2014 \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u2014 \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439\/\u0441\u0435\u043a\u0443\u043d\u0434\u0443<\/li>\n<\/ul>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u044f \u0437\u0430\u043c\u0435\u0440\u0438\u043b \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044f\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e:  <\/p>\n<ul>\n<li>testFieldSaveAccessible \u2014 \u0434\u043e\u0441\u0443\u043f \u043a \u043f\u043e\u043b\u044e \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c setAccessible(true) \u043d\u0430 Field<\/li>\n<li>testFieldSaveNotAccessible \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0434\u043d\u044f\u0442\u044b\u0439 Field<\/li>\n<li>testFieldStraighforward \u2014 \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430<\/li>\n<\/ul>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u0441\u0442, \u0438\u0437\u043c\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044f\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS) @State(Scope.Thread) public class ReflectionFieldAccess { \t \tprivate static final Class&lt;TestedClass&gt; clazz = TestedClass.class; \t \tprivate TestedClass testedObject; \t \tField simpleField; \tField fieldAccessible; \t \t@Setup \tpublic void init() { \t\ttry { \t\t\ttestedObject = new TestedClass(); \t\t\t \t\t\tsimpleField = clazz.getField(&quot;a&quot;);  \t\t\tField Field = clazz.getField(&quot;b&quot;); \t\t\tField.setAccessible(true); \t\t\tfieldAccessible = Field; \t\t} catch (Exception e) { \t\t\t\/\/ do nothing \t\t} \t}  \t@GenerateMicroBenchmark \tpublic Object testFieldSaveAccessible() throws Exception { \t\treturn fieldAccessible.get(testedObject); \t}  \t@GenerateMicroBenchmark \tpublic Object testFieldSaveNotAccessible() throws Exception { \t\treturn simpleField.get(testedObject); \t}  \t@GenerateMicroBenchmark \tpublic Object testFieldStraighforward() throws Exception { \t\treturn testedObject.c; \t} } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u0441\u0442, \u0438\u0437\u043c\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u043e\u043b\u044f\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS) @State(Scope.Thread) public class ReflectionFieldStaticAccess { \t \tprivate static final Class&lt;TestedClass&gt; clazz = TestedClass.class; \t \tField simpleField; \tField fieldAccessible; \t \t@Setup \tpublic void init() { \t\ttry { \t\t\tsimpleField = clazz.getField(&quot;aStat&quot;);  \t\t\tField Field = clazz.getField(&quot;bStat&quot;); \t\t\tField.setAccessible(true); \t\t\tfieldAccessible = Field; \t\t} catch (Exception e) { \t\t\t\/\/ do nothing \t\t} \t}  \t@GenerateMicroBenchmark \tpublic Object testFieldSaveAccessible() throws Exception { \t\treturn fieldAccessible.get(null); \t}  \t@GenerateMicroBenchmark \tpublic Object testFieldSaveNotAccessible() throws Exception { \t\treturn simpleField.get(null); \t}  \t@GenerateMicroBenchmark \tpublic Object testFieldStraighforward() throws Exception { \t\treturn TestedClass.cStat; \t} } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f JDK7:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/c75\/535\/022\/c755350227d0d6c456fdeeb9e1f1a597.png\"\/><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f JDK8:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/01e\/826\/694\/01e8266947de93ec6daeb8a5cea08b70.png\"\/><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/c38\/4a9\/3d5\/c384a93d50c9ffeed84950732db2c71c.png\"\/><br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/581\/535\/0df\/5815350dfd99b5884e29eed0d20f6333.png\"\/><\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b:  <\/p>\n<ol>\n<li>\u041f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 setAccessible(true) \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0430\u0432<\/li>\n<li>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044f\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 2 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0447\u0435\u0440\u0435\u0437 reflection<\/li>\n<li>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0447\u0442\u043e \u0432 jdk8 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0447\u0435\u0440\u0435\u0437 reflection<\/li>\n<\/ol>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0437\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0432\u044b\u0431\u043e\u0440 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432.<br \/>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API MethodHandle, \u0447\u0430\u0441\u0442\u044c JSR 292, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e c jdk7.  <\/p>\n<ul>\n<li>testFastMethod \u2014 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c FastMethod \u0438\u0437 CGLIB<\/li>\n<li>testMethodNotAccessible \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 reflection<\/li>\n<li>testMethodAccessible \u2014 \u0432\u044b\u0437\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 reflection \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c setAccessible(true) \u043d\u0430 Method<\/li>\n<li>testMethodHandle \u2014 \u0432\u044b\u0437\u043e\u0432 MethodHandle.invoke<\/li>\n<li>testMethodHandleExact \u2014 \u0432\u044b\u0437\u043e\u0432 MethodHandle.invokeExact, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0435\u043c \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432<\/li>\n<\/ul>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u0441\u0442, \u0438\u0437\u043c\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS) @State(Scope.Thread) public class ReflectionMethodAccess { \t \tprivate static final Class&lt;TestedClass&gt; clazz = TestedClass.class; \t \tprivate TestedClass testedObject; \t \tMethod simpleMethod; \tMethod methodAccessible; \tFastMethod fastMethod; \tMethodHandle methodHandle; \t \t@Setup \tpublic void init() { \t\ttry { \t\t\ttestedObject = new TestedClass(); \t\t\t \t\t\tsimpleMethod = clazz.getMethod(&quot;getA&quot;, null);  \t\t\tMethod method = clazz.getMethod(&quot;getB&quot;, null); \t\t\tmethod.setAccessible(true); \t\t\tmethodAccessible = method; \t\t\t \t\t\tfastMethod = FastClass.create(clazz).getMethod(&quot;getC&quot;, null); \t\t\t \t\t\tmethodHandle = MethodHandles.lookup().findVirtual(clazz, &quot;getD&quot;, MethodType.methodType(Integer.class)); \t\t} catch (Exception e) { \t\t\t\/\/ do nothing \t\t} \t}  \t@GenerateMicroBenchmark \tpublic Object testFastMethod() throws Throwable { \t\treturn fastMethod.invoke(testedObject, null); \t} \t \t@GenerateMicroBenchmark \tpublic Object testMethodAccessible() throws Throwable { \t\treturn methodAccessible.invoke(testedObject, null); \t}  \t@GenerateMicroBenchmark \tpublic Object testMethodNotAccessible() throws Throwable { \t\treturn simpleMethod.invoke(testedObject, null); \t} \t \t@GenerateMicroBenchmark \tpublic Object testMethodHandleExact() throws Throwable { \t\treturn (Integer)methodHandle.invokeExact(testedObject); \t} \t \t@GenerateMicroBenchmark \tpublic Object testMethodHandle() throws Throwable { \t\treturn (Integer)methodHandle.invoke(testedObject); \t}   \t@GenerateMicroBenchmark \tpublic Object testMethodDirect() throws Throwable { \t\treturn testedObject.getA(); \t} } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u0441\u0442, \u0438\u0437\u043c\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS) @State(Scope.Thread) public class ReflectionMethodStaticAccess { \t \tprivate static final Class&lt;TestedClass&gt; clazz = TestedClass.class; \t \tMethod simpleMethod; \tMethod methodAccessible; \tMethodHandle methodHandle; \tFastMethod fastMethod; \t \t@Setup \tpublic void init() { \t\ttry { \t\t\tsimpleMethod = clazz.getMethod(&quot;getAStatic&quot;, null);  \t\t\tMethod method = clazz.getMethod(&quot;getBStatic&quot;, null); \t\t\tmethod.setAccessible(true); \t\t\tmethodAccessible = method; \t\t \t\t\tfastMethod = FastClass.create(clazz).getMethod(&quot;getCStatic&quot;, null); \t\t\t \t\t\tmethodHandle = MethodHandles.lookup().findStatic(clazz, &quot;getDStatic&quot;, MethodType.methodType(Integer.class)); \t\t} catch (Exception e) { \t\t\t\/\/ do nothing \t\t} \t}  \t@GenerateMicroBenchmark \tpublic Object testFastMethod() throws Throwable { \t\treturn fastMethod.invoke(null, null); \t}  \t@GenerateMicroBenchmark \tpublic Object testMethodAccessible() throws Throwable { \t\treturn methodAccessible.invoke(null, null); \t}   \t@GenerateMicroBenchmark \tpublic Object testMethodNotAccessible() throws Throwable { \t\treturn simpleMethod.invoke(null, null); \t} \t \t@GenerateMicroBenchmark \tpublic Object testMethodHandleExact() throws Throwable { \t\treturn (Integer)methodHandle.invokeExact(); \t} \t \t@GenerateMicroBenchmark \tpublic Object testMethodHandle() throws Throwable { \t\treturn (Integer)methodHandle.invoke(); \t}  \t@GenerateMicroBenchmark \tpublic Object testMethodDirect() throws Throwable { \t\treturn TestedClass.getAStatic(); \t} } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e MethodHandle \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043b\u0443\u0448\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <a href=\"http:\/\/www.youtube.com\/watch?v=oeFejrCcqDI\">\u0434\u043e\u043a\u043b\u0430\u0434\u0435 \u0412\u043b\u0430\u0434\u0438\u043c\u0438\u0440\u0430 \u0418\u0432\u0430\u043d\u043e\u0432\u0430 \u043f\u0440\u043e invokedynamics <\/a><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f JDK7:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/558\/138\/4ea\/5581384ea38142efcb2faf87c8c1a501.png\"\/><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f JDK8:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/828\/e10\/be7\/828e10be7aacbd9922ef84b67b960bf1.png\"\/><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/716\/003\/cb8\/716003cb82b3d0324abfa4b9b91579de.png\"\/><br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/e7a\/828\/912\/e7a828912eca503612f94b91f7abdee3.png\"\/><\/p>\n<p>  \u0418\u0437 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432:  <\/p>\n<ol>\n<li>\u041f\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c \u043c\u043d\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c FastMethod \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u043d\u0430 jdk7, \u043d\u0430 jdk8 \u0436\u0435 \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 2 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u2014 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u0443 \u0441 setAccessible(true) (\u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438)<\/li>\n<li>\u0412 jdk8 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 MethodHandle.invoke, \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043b\u044f\u043c\u0431\u0434\u0430\u043c\u0438<\/li>\n<li>\u041e\u0431\u0449\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c reflection \u0432\u044b\u0440\u043e\u0441\u043b\u0430, \u043a\u0430\u043a \u0438 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f \u0441 \u043f\u043e\u043b\u044f\u043c\u0438<\/li>\n<\/ol>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 reflection \u2014 \u0442\u043e \u0432\u043e\u0442 \u0432\u0430\u043c \u043b\u0438\u0448\u043d\u0438\u0439 \u043f\u043e\u0432\u043e\u0434 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043d\u0430 jdk8.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u043c, \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c reflection \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0438\u043b\u0438 \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u043e \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/SerCeMan\/reflection-access-tests\">\u043d\u0430 github<\/a>.<\/p>\n<p>  P.S. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0442\u0435 \u0438\u043b\u0438 \u0438\u043d\u044b\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b, \u043f\u043e\u0432\u043b\u0438\u044f\u0432\u0448\u0438\u0435 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.  \t\t\t\t<\/p>\n<div class=\"polling\">\n<form action=\"\/json\/polling\/\" class=\"poll\" method=\"post\">\n<div class=\"poll_title\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043b\u0438 \u0432\u044b reflection \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445?<\/div>\n<p>  \t\t<input type=\"hidden\" name=\"post_id\" value=\"216435\"\/> \t\t<input type=\"hidden\" name=\"polling_question_id\" value=\"10681\"\/>  \t\t<\/p>\n<table class=\"answer\">\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv54277\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"54277\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv54277\">\u0414\u0430, reflection<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv54279\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"54279\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv54279\">\u0414\u0430, reflection \u0438 MethodHandle<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv54281\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"54281\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv54281\">\u0422\u043e\u043b\u044c\u043a\u043e MethodHandle<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv54283\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"54283\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv54283\">\u041d\u0435\u0442<\/label> \t\t\t\t<\/td>\n<\/tr>\n<\/table>\n<p class=\"for_users_only_msg\">\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a href=\"https:\/\/auth.habrahabr.ru\/login\/\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/p>\n<p class=\"total\">\u041d\u0438\u043a\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b. \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043d\u0435\u0442.<\/p>\n<\/p><\/form>\n<\/p><\/div>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/216435\/\"> http:\/\/habrahabr.ru\/post\/216435\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e, \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0443\u044f \u043f\u043e \u043a\u043e\u0434\u0443 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430\u0431\u0440\u0435\u043b \u043d\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 spring \u0431\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (\u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043b\u0435\u0442\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432) \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 reflection. \u0412 \u0431\u0438\u043d\u0435 \u0443\u0436\u0435 \u0431\u044b\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u044d\u0448 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432, \u043e\u0434\u043d\u0430\u043a\u043e \u044f \u0437\u0430\u0434\u0430\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u2014 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440 reflection \u0438 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/74d\/574\/e80\/74d574e800e2413c2c803094efde750a.png\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-216435","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/216435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216435"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/216435\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}