C++ 定义默认值void locals_index(int reg, int offset = 1);
看jvm源码的时候怎么也看不懂,来回看了几次了就是关于iload 6 指令的解析
def(Bytecodes::_lload , ubcp|____|____|____, vtos, ltos, lload , _ );
看重载的def函数
const char _ = ' ';
const int ____ = 0;
其中的_ 是上面的定义
void TemplateTable::def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(), char filler) {
assert(filler == ' ', "just checkin'");
def(code, flags, in, out, (Template::generator)gen, 0);
}
//下面对应的有参函数 对应上面的无参函数
void TemplateTable::def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg), int arg) {
// should factor out these constants
const int ubcp = 1 << Template::uses_bcp_bit;
const int disp = 1 << Template::does_dispatch_bit;
const int clvm = 1 << Template::calls_vm_bit;
const int iswd = 1 << Template::wide_bit;
// determine which table to use
bool is_wide = (flags & iswd) != 0;
// make sure that wide instructions have a vtos entry point
// (since they are executed extremely rarely, it doesn't pay out to have an
// extra set of 5 dispatch tables for the wide instructions - for simplicity
// they all go with one table)
assert(in == vtos || !is_wide, "wide instructions have vtos entry point only");
Template* t = is_wide ? template_for_wide(code) : template_for(code);
// setup entry
t->initialize(flags, in, out, gen, arg);
assert(t->bytecode() == code, "just checkin'");
}
上面没有什么能明白调用了无参的gen()函数,那么就是
void TemplateTable::iload() {
transition(vtos, itos);
if (RewriteFrequentPairs) {
Label rewrite, done;
// get next byte
__ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
// if _iload, wait to rewrite to iload2. We only want to rewrite the
// last two iloads in a pair. Comparing against fast_iload means that
// the next bytecode is neither an iload or a caload, and therefore
// an iload pair.
__ cmpl(rbx, Bytecodes::_iload);
__ jcc(Assembler::equal, done);
__ cmpl(rbx, Bytecodes::_fast_iload);
__ movl(rcx, Bytecodes::_fast_iload2);
__ jccb(Assembler::equal, rewrite);
// if _caload, rewrite to fast_icaload
__ cmpl(rbx, Bytecodes::_caload);
__ movl(rcx, Bytecodes::_fast_icaload);
__ jccb(Assembler::equal, rewrite);
// rewrite so iload doesn't check again.
__ movl(rcx, Bytecodes::_fast_iload);
// rewrite
// rcx: fast bytecode
__ bind(rewrite);
patch_bytecode(Bytecodes::_iload, rcx, rbx, false);
__ bind(done);
} //以上忽略
// Get the local value into tos
locals_index(rbx);
__ movl(rax, iaddress(rbx));
}
接下来
void TemplateTable::locals_index(Register reg, int offset) {
__ load_unsigned_byte(reg, at_bcp(offset));
__ negptr(reg);
}
我开始找 locals_index() 函数,只有这个两个参数的,以为有重载,结果没有,然后查资料说是有,可以省略参数,就将0作为默认参数,就不需要写这个0了
locals_index(rbx,0)
但是逻辑不符合,应该是 locals_index(rbx,1)才对
于是又发现在hpp文件中有一个定义
static void locals_index(Register reg, int offset = 1);
莫非这个意思是设置默认值,然后省略了 1 ?
在本地做了实验
main.hpp #ifndef UNTITLED2_MAIN_H
#define UNTITLED2_MAIN_H #endif //UNTITLED2_MAIN_H
static void locals_index(int reg, int offset = 1); main.cpp #include<stdio.h>
#include "main.h" int main(int argc, char* argv[]){ locals_index(1);
return 0;
} void locals_index(int reg, int offset){
printf("c=%d\n",reg+offset);
} //控制台打印
C:\Users\meto\CLionProjects\untitled2\cmake-build-debug\untitled2.exe
c=2 Process finished with exit code 0
果然是这个样子,说明了c++有默认值的用法
小c佳,你这样子不好,让我好一顿找
C++ 定义默认值void locals_index(int reg, int offset = 1);的更多相关文章
- [水煮 ASP.NET Web API2 方法论](3-3)路由默认值
问题 如何为路由中参数设置默认值. 解决方案 不管使用属性路由还是集中式路由,ASP.NET WEB API 都可以很方便的为路由定义默认参数.在每次客户端请求的时候,如果客户端没有传这些参数,框架会 ...
- 【C#基础概念】函数参数默认值和指定传参和方法参数
函数参数默认值和指定传参 最近在编写代码时发现介绍C#参数默认值不能像PL/SQL那样直接设置default,网上也没有太多详细的资料,自己琢磨并试验后整理成果如下: C#允许在函数声明部分定义默认值 ...
- java 8种基本数据类型的默认值及所占字节数
通过一段代码来测试一下 8种基本数据类型的默认值 package dierge; public class Ceshi { int a; double b; boolean c; char d; fl ...
- java中8种数据类型和默认值所占字节数
java 8种基本数据类型的默认值及所占字节数 通过一段代码来测试一下 8种基本数据类型的默认值 1 package dierge; 2 3 public class Ceshi { 4 int a; ...
- js中function参数默认值
--在dreamweaver做网站时,函数定义是在一个*.js文件中,其中定义了一个func,有四个参数,function func(string1,url,flag,icon),然后在另一个asp中 ...
- sql的基本用法-------修改字段默认值和属性
修改表中已有的字段属性 ALTER TABLE 表名 ALTER COLUMN 字段名 varchar(500) --sqlserver建表表时设置字段的默认值 create table 表(id i ...
- C# 3.0 { get; set; } 默认值
.NET Framework 3.5 使用的是 C# 3.0,C# 3.0 有一些新的语言特性,其中有一项就是快捷属性. 之前的写法: private int _id = 0;public int I ...
- JS中给函数参数添加默认值
最近在Codewars上面看到一道很好的题目,要求用JS写一个函数defaultArguments,用来给指定的函数的某些参数添加默认值.举例来说就是: // foo函数有一个参数,名为x var f ...
- SQL Server 删除表的默认值约束
首先查出字段的默认值约束名称,然后根据默认值约束名称删除默认值约束 ) select @constraintName = b.name from syscolumns a,sysobjects b w ...
随机推荐
- 13:Linux虚拟机网络连接异常
这两个服务需要启动
- NOIP模拟测试28「阴阳·虎·山洞」
写这几个题解我觉得我就像在按照官方题解抄一样 阴阳 题解 将题目中给的阴阳看作黑色和白色 首先我们观察到最后生成图中某种颜色必须是竖着单调递增或竖着单调递减 类似这样 否则不满足这个条件 但合法染色方 ...
- Golang学习(用代码来学习) - 第三篇
type Books struct { title string author string subject string id int } /** 结构体的学习 */ func struct_tes ...
- js中有对象的key怎么获取对应的值
一般人的思路是这样的 var obj = {"name1":"张三","name2":"李四"}; var key = ...
- el-upload上传列表实现 展开 收起
# el-upload上传列表实现 展开 收起 #### 无图言*,所以先上最终效果图(想参考代码的可以直接滑到最后) ### 具体实现思路 注意: 每个人的项目环境以及需求,都不尽相同,所以这里仅仅 ...
- excel函数提取内容中的汉字
RIGHT(A2,LENB(A2)-LEN(A2)) 函数LENB将每个汉字(双字节字符)的字符数按2计数,LEN函数则对所有的字符都按1计数.因此"LENB(A2)-LEN(A2)&quo ...
- Typecho 安装教程 -- Linux
1.下载宝塔面板 1 使用 SSH 连接工具,如堡塔SSH终端连接到您的 Linux 服务器后,挂载磁盘,根据系统执行相应命令开始安装(大约2分钟完成面板安装): 2 Centos安装脚本 yum i ...
- hive学习笔记之十:用户自定义聚合函数(UDAF)
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本文是<hive学习笔记>的第十 ...
- Java进阶 | IO流核心模块与基本原理
一.IO流与系统 IO技术在JDK中算是极其复杂的模块,其复杂的一个关键原因就是IO操作和系统内核的关联性,另外网络编程,文件管理都依赖IO技术,而且都是编程的难点,想要整体理解IO流,先从Linux ...
- hadoop学习(一)环境的搭建
1.安装几台Linux虚拟机.安装的过程就不赘述了,网上教程很多.win7系统上装了一个VMWare,因为一些原因,VMWare版本不是最新的,是VMWare7.1版本,由于VMWare版本不高,所以 ...